I was surprised to see these bits of fiddlefaddle online:
The Tao of Tcl
A Class Code Generator
Saturday, August 9, 2014
Wednesday, July 16, 2014
Building RESTful APIs with Tornado
Nice Tornado Article.
http://www.drdobbs.com/open-source/building-restful-apis-with-tornado/240160382
http://www.drdobbs.com/open-source/building-restful-apis-with-tornado/240160382
from datetime import dateimport tornado.escapeimport tornado.ioloopimport tornado.webclass VersionHandler(tornado.web.RequestHandler): def get(self): response = { 'version': '3.5.1', 'last_build': date.today().isoformat() } self.write(response)class GetGameByIdHandler(tornado.web.RequestHandler): def get(self, id): response = { 'id': int(id), 'name': 'Crazy Game', 'release_date': date.today().isoformat() } self.write(response)application = tornado.web.Application([ (r"/getgamebyid/([0-9]+)", GetGameByIdHandler), (r"/version", VersionHandler)])if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start()The Night Watch
One of the most awesome computer papers ever written!
http://research.microsoft.com/en-us/people/mickens/thenightwatch.pdf
http://research.microsoft.com/en-us/people/mickens/thenightwatch.pdf
When you debug a distributed system or an OS kernel, you do it Texas-style. You gather some mean, stoic people, people who have seen things die, and you get some primitive tools, like a compass and a rucksack and a stick that’s pointed on one end, and you walk into the wilderness and you look for trouble, possibly while using chewing tobacco. As a systems hacker, you must be prepared to do savage things, unspeakable things, to kill runaway threads with your bare hands, to write directly to network ports using telnet and an old copy of an RFC that you found in the Vatican. When you debug systems code, there are no high-level debates about font choices and the best kind of turquoise, because this is the Old Testament, an angry and monochromatic world, and it doesn’t matter whether your Arial is Bold or Condensed when people are covered in boils and pestilence and Egyptian pharaoh oppression. HCI people discover bugs by receiving a concerned email from their therapist. Systems people discover bugs by waking up and discovering that their first-born children are missing and “ETIMEDOUT” has been written in blood on the wall.
Tuesday, July 15, 2014
Mechanical Soup: A Python library for automating interaction with websites
MechanicalSoup automatically stores and sends cookies, follows redirects, and can follow links and submit forms. It doesn't do Javascript.
Monday, June 16, 2014
Linux: Invalidating Cache
Here's the incantation for invalidating the linux file system cache. Good for running performance tests when you don't want a hot cache throwing off the results.
sudo sh -c 'sync;echo 3 > /proc/sys/vm/drop_caches'
sudo sh -c 'sync;echo 3 > /proc/sys/vm/drop_caches'
Tuesday, June 10, 2014
Pymunk
"pymunk is a easy-to-use pythonic 2d physics library that can be used whenever you need 2d rigid body physics from Python."
https://github.com/viblo/pymunk
https://github.com/viblo/pymunk
Friday, April 4, 2014
Tuesday, April 1, 2014
Simple C Web Server
Here's a nice example of practical network programming in C, about 200 loc.
http://www.ibm.com/developerworks/systems/library/es-nweb/index.html
http://www.ibm.com/developerworks/systems/library/es-nweb/index.html
Two Interesting Articles on UDP
Should you use UDP in your game? Here's two interesting points of view.
Wednesday, February 19, 2014
Friday, January 24, 2014
Publishing via Github Pages
Here's two intros. Razius uses pelican, and 24ways uses jekyll, but the idea is the same. Generate static HTML via some markup language, push to github, and it's viewable. And of course, there's good instructions on the Github Pages site itself.
Update: maybe good for publishing via S3?
Update: maybe good for publishing via S3?
Tuesday, May 21, 2013
jq - like sed for JSON
Over on github, a potentially nifty JSON processor.
jq is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.
jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, scp it to a far away machine, and expect it to work.
jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you’d expect.
Tuesday, April 9, 2013
Tuesday, April 2, 2013
Various Oracle Data Dictionary Queries
adapted from here.
TABLES
select distinct lower(table_name) as table_name
from user_tab_columns
order by 1
SEQUENCES
select lower(sequence_name) as sequence_name,
min_value,
max_value,
increment_by,
cycle_flag,
order_flag,
cache_size
from user_sequences
order by 1
FOREIGN KEYS
select ucc.constraint_name,
ucc.column_name,
fc.table_name
from user_cons_columns ucc,
user_constraints fc,
user_constraints uc
where uc.constraint_type = 'R' and
uc.constraint_name = ucc.constraint_name and
fc.constraint_name = uc.r_constraint_name and
uc.table_name='%s'
order by 1, 2
DESC
select column_name as name,
data_type as type,
char_length as length,
nullable,
data_default as "default"
from user_tab_columns
where table_name='%s'
order by column_name
CONSTRAINTS
select ucc.constraint_name,
ucc.column_name,
uc.constraint_type,
uc.search_condition
from user_constraints uc,
user_cons_columns ucc
where uc.constraint_name = ucc.constraint_name and
uc.table_name='%s' and
uc.constraint_type = 'C'
order by ucc.constraint_name, ucc.position
TRIGGERS
select trigger_name,
trigger_type,
triggering_event,
table_name,
description,
trigger_body
from user_triggers
order by 1
LIST_INDEX
select case
when constraint_type = 'P' then 'PRIMARY KEY'
else ' ' end as index_type,
ui.index_name,
ui.uniqueness,
uic.column_name,
uic.column_position,
uic.descend
from user_indexes ui
join user_ind_columns uic on uic.index_name = ui.index_name
left join user_constraints
on user_constraints.constraint_name = ui.index_name and
user_constraints.constraint_type = 'P'
where ui.table_name = '%s'
order by constraint_type, uic.column_position;
INDEX
select case
when constraint_type = 'P' then 'PRIMARY KEY'
else ' ' end as index_type,
ui.table_name,
ui.index_name,
ui.uniqueness,
uic.column_name,
uic.column_position,
uic.descend
from user_indexes ui
join user_ind_columns uic on uic.index_name = ui.index_name
left join user_constraints
on user_constraints.constraint_name = ui.index_name and
user_constraints.constraint_type = 'P'
where ui.index_name = '%s'
order by constraint_type, uic.column_position;
TABLES
select distinct lower(table_name) as table_name
from user_tab_columns
order by 1
SEQUENCES
select lower(sequence_name) as sequence_name,
min_value,
max_value,
increment_by,
cycle_flag,
order_flag,
cache_size
from user_sequences
order by 1
FOREIGN KEYS
select ucc.constraint_name,
ucc.column_name,
fc.table_name
from user_cons_columns ucc,
user_constraints fc,
user_constraints uc
where uc.constraint_type = 'R' and
uc.constraint_name = ucc.constraint_name and
fc.constraint_name = uc.r_constraint_name and
uc.table_name='%s'
order by 1, 2
DESC
select column_name as name,
data_type as type,
char_length as length,
nullable,
data_default as "default"
from user_tab_columns
where table_name='%s'
order by column_name
CONSTRAINTS
select ucc.constraint_name,
ucc.column_name,
uc.constraint_type,
uc.search_condition
from user_constraints uc,
user_cons_columns ucc
where uc.constraint_name = ucc.constraint_name and
uc.table_name='%s' and
uc.constraint_type = 'C'
order by ucc.constraint_name, ucc.position
TRIGGERS
select trigger_name,
trigger_type,
triggering_event,
table_name,
description,
trigger_body
from user_triggers
order by 1
LIST_INDEX
select case
when constraint_type = 'P' then 'PRIMARY KEY'
else ' ' end as index_type,
ui.index_name,
ui.uniqueness,
uic.column_name,
uic.column_position,
uic.descend
from user_indexes ui
join user_ind_columns uic on uic.index_name = ui.index_name
left join user_constraints
on user_constraints.constraint_name = ui.index_name and
user_constraints.constraint_type = 'P'
where ui.table_name = '%s'
order by constraint_type, uic.column_position;
INDEX
select case
when constraint_type = 'P' then 'PRIMARY KEY'
else ' ' end as index_type,
ui.table_name,
ui.index_name,
ui.uniqueness,
uic.column_name,
uic.column_position,
uic.descend
from user_indexes ui
join user_ind_columns uic on uic.index_name = ui.index_name
left join user_constraints
on user_constraints.constraint_name = ui.index_name and
user_constraints.constraint_type = 'P'
where ui.index_name = '%s'
order by constraint_type, uic.column_position;
Monday, April 1, 2013
Interesting way to generate some Oracle sample tables
A lot of times you need to create a sample table with a primary and foreign key, populated with some kind of name-like field. Here's an interesting way to do it.
create table emp_tab as
select
rownum empno,
object_name ename,
mod(rownum, 10) + 1 deptno,
rownum * 100 sal
from all_objects
where rownum < 100;
Now you can do the same thing, for the foreign key.
create table dept_tab as
select
rownum deptno,
'd_' || rownum deptname
from all_objects
where rownum <= 10;
mh@templar> select * from emp_tab;
empno ename deptno sal
----- ----- ------ ---
1 DUAL 2 100
2 DUAL 3 200
3 SYSTEM_PRIVILEGE_MAP 4 300
4 SYSTEM_PRIVILEGE_MAP 5 400
5 TABLE_PRIVILEGE_MAP 6 500
6 TABLE_PRIVILEGE_MAP 7 600
create table emp_tab as
select
rownum empno,
object_name ename,
mod(rownum, 10) + 1 deptno,
rownum * 100 sal
from all_objects
where rownum < 100;
Now you can do the same thing, for the foreign key.
create table dept_tab as
select
rownum deptno,
'd_' || rownum deptname
from all_objects
where rownum <= 10;
mh@templar> select * from emp_tab;
empno ename deptno sal
----- ----- ------ ---
1 DUAL 2 100
2 DUAL 3 200
3 SYSTEM_PRIVILEGE_MAP 4 300
4 SYSTEM_PRIVILEGE_MAP 5 400
5 TABLE_PRIVILEGE_MAP 6 500
6 TABLE_PRIVILEGE_MAP 7 600
Thursday, May 31, 2012
Latency numbers every programmer should know — Gist
Latency numbers every programmer should know — Gist:
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
Read 1 MB sequentially from disk 20,000,000 ns
Send packet CA->Netherlands->CA 150,000,000 ns
By Jeff Dean (http://research.google.com/people/jeff/):
Tuesday, March 6, 2012
A note from Donald Knuth about The Art of Computer Programming
A while back I answered a question on Stack Overflow asking about the relative popularity of The Art of Computer Programming. I replied with something I had heard, that he had commented that they were the "most purchased, least read" computer book in the world. One Stack Overflow user, ShreevatsaR, had the good sense to call BS on my unsourced attribution.
By way of contrition, I sent the attached note to Knuth (we had met a couple of times previously -- enough to give me some hope of a response) asking him to confirm or deny. Attached is his response. We followed up with lunch, and he spoke quite approvingly of Stack Overflow. I think the Math Stack people at the time were working Tex in the Stack markup language, and they had been in communication with him as well.He responded right away:
I have to say that the phrase isn't particular apt, since there obviously exist computer science books less read than TAOCP. It is true that the *ratio* of pages-thoroughly-read to pages-purchased is pretty low for TAOCP, because different people are interested in different pages. But still I like to think that the pages read are so great that the buyers aren't unhappy overall. (Or else they just want their friends to think that they have mastered a lot of tough material, which I must confess is not easy for anybody I know including myself. Einstein said it best: 'Make things as simple as possible but no simpler.' Some theories are inherently unsimplifiable ... we can even *prove* that!)
My favorite related comment is the enclosed ad that ran about ten years ago, when it was rumored that John Grisham was thinking of responding by writing a seven-volume treatise.
Anyway the bottom line is that I'm enthused about sending a memo to The Internet about this particular phrase. The web has thousands of tales that aren't true, about virtually everybody in public life. (Including the story about me and Pixar's CEO.) I *did* say things like 'Premature optimization is the root of all evil in programming' and 'Beware of bugs in the above code -- I've only proved it correct not actually run it.'

I especially like that he marked up my original note and fixed a grammatical error!
Thanks again to the most excellent ShreevatsaR who prompted me to do this!
Sunday, February 5, 2012
blog.bjrn.se: Let’s build an MP3-decoder!
blog.bjrn.se: Let’s build an MP3-decoder!: Even though MP3 is probably the single most well known file format and codec on Earth, it’s not very well understood by most programmers – for many encoders/decoders is in the class of software “other people” write, like standard libraries or operating system kernels. This article will attempt to demystify the decoder, with short top-down primers on signal processing and information theory when necessary. Additionally, a small but not full-featured decoder will be written (in Haskell), suited to play around with.
Monday, August 30, 2010
Oracle Packages that include Java
Here's a cheat sheet for including Java stored procedures in packages.
Write a class:
public class OracleFoo {
public static void myproc(int port, String s) throws Exception {
}
}
Compile and Load:
javac OracleFoo.java
loadjava -u scott/tiger OracleFoo.class
Declare a package:
create or replace package oraclefoo
as
procedure myproc(port number, s varchar2)
as language java name 'OracleFoo.myproc(int, java.lang.String)';
end;
Call:
begin
oracletbslow.myproc(7728,'[1,"a","b1",{}]');
oracletbslow.myproc(7727,'[1,"a","b2",{}]');
end;
Permissions:
need to set these, double-check notes...
public class OracleFoo {
public static void myproc(int port, String s) throws Exception {
}
}
Compile and Load:
javac OracleFoo.java
loadjava -u scott/tiger OracleFoo.class
Declare a package:
create or replace package oraclefoo
as
procedure myproc(port number, s varchar2)
as language java name 'OracleFoo.myproc(int, java.lang.String)';
end;
Call:
begin
oracletbslow.myproc(7728,'[1,"a","b1",{}]');
oracletbslow.myproc(7727,'[1,"a","b2",{}]');
end;
Permissions:
need to set these, double-check notes...
Wednesday, August 25, 2010
Six Keys to Being Excellent at Anything - Tony Schwartz - The Conversation - Harvard Business Review
Six Keys to Being Excellent at Anything - Tony Schwartz - The Conversation - Harvard Business Review:
- Pursue what you love.
- Do the hardest work first.
- Practice intensely
- Seek expert feedback, in intermittent doses.
- Take regular renewal breaks.
- Ritualize practice.
Subscribe to:
Posts (Atom)
-
A while back I answered a question on Stack Overflow asking about the relative popularity of The Art of Computer Programming . I replied wit...
-
Here's a quick example of duckdb's new ASOF JOIN. Problem: we have a time-based price table; if you have a sale time that falls in t...
-
First, let's draw a cube: cube(10,true); Now, let's animate a 360 degree turntable view of the cube: rotate([0,0,$...
