| *Camp |
[Oct. 9th, 2007|12:56 pm] |
Neil Blakey-Milner (nbm) has recently asked people to talk about *Camp, so I shall.
The idea is very similar BarCamp which is, in turn, based on Foo Camp. Get a bunch of geeks together, add pizza and a platform to talk about interesting stuff, stir well and see what happens.
If this sounds interesting to you and you are able to be in Cape Town on the 8th and/or 9th of December, come along. If you're feeling up to it, sign up to the planning list and look at the planning wiki. |
|
|
| Houses and hacking |
[Oct. 7th, 2007|04:11 pm] |
As of this afternoon, I have the keys to my new (temporary) residence in Observatory. It has two spare bedrooms, so if you want to visit me in Cape Town, do it before the end of January. :-)
I have been playing with Project Euler quite a bit recently. It's a fun little project where they give you a bunch of short mathematical programming problems. Most of the problems are less than an hour's work to solve, although there are a few that take longer. I've been using them to get some Erlang experience, and you can find my solutions in a darcs repository at http://darcs.jerith.za.net/projecteuler/ or you can grab projecteuler.erl directly. |
|
|
| Higher order functions in bash |
[Jul. 13th, 2007|10:07 am] |
I recently had occasion to refactor a bunch of bash scripts, and one of the problems was that certain loop constructs were cropping up a lot. A quick search didn't turn up a way to do higher order functions in bash, so I (re)invented one:
higher_order() {
# some code
eval "$1"
# some more code
} The eval evaluates the code passed as a parameter, although for anything nontrivial this should probably be a function name.
Here's a slightly more concrete example:
do_twice()
{
for i in `seq 2`; do
eval "$1"
done
}
hello() {
echo "Hello $1"
}
do_twice 'hello world' Update:
I wrote up a more complete version over at my website and have just added a bunch more toys to it. |
|
|
| Commandline router stuff |
[Jun. 29th, 2007|10:30 pm] |
So, I finally spent an evening struggling with my WRT54G3G's web interface and managed to craft a pair of commandline tools to connect and disconnect:
wrtconnect.sh: #!/bin/bash read -s -p "Please enter your password: " WRTPWD curl -o /dev/null -# -d submit_button=index -d change_action=gozila_cgi -d submit_type=Connect_wwan http://admin:${WRTPWD}@10.0.0.1/apply.cgi
wrtdisconnect.sh: #!/bin/bash read -s -p "Please enter your password: " WRTPWD curl -o /dev/null -# -d submit_button=index -d change_action=gozila_cgi -d submit_type=Disconnect_wwan http://admin:${WRTPWD}@10.0.0.1/apply.cgi
They're not perfect and the router is unresponsive for a couple of minutes after using either, but it's still better than having to launch firefox just to hit the web interface. (With all the JS crud in there, lynx isn't an option.)
Also, it appears there's new firmware for the thing. I've downloaded it and will give it a shot over the weekend. With luck it'll fix the failure to look for 3g signal issue. |
|
|
| ORDER OF THE SCIENCE SCOUTS OF EXEMPLARY REPUTE AND ABOVE AVERAGE PHYSIQUE |
[Jun. 7th, 2007|03:13 pm] |
I recently rediscovered the ORDER OF THE SCIENCE SCOUTS OF EXEMPLARY REPUTE AND ABOVE AVERAGE PHYSIQUE and decided to post the set of badges I qualify for.
 The "talking science" badge.
I'm an engineer and a programmer with a strong interest in all things scientific. I talk about it a lot. Just not on my blog so much.
 The "MacGyver" badge.
I carry a leatherman. I improvise tools and devices quite a lot.
 The "I'm pretty confident around an open flame" badge.
I haven't burned anything (important) down yet...
 The "destroyer of quackery" badge.
I have debunked ID (and related quackery) at quite a number of people.
 The "I may look like a scientist but I'm actually also a ninja" badge.
A cunning ninja, full of stealth and martial skill.
 The "my degree inadvertantly makes me competent in fixing household appliances" badge.
I try to avoid this, but my Electronic Engineering degree means I end up doing it far too often.
 The "has frozen stuff just to see what happens" badge. (LEVEL III)
Great stuff for cooling beverages. Even better for playing with superconductors and magnets...
 The "I bet I know more computer languages than you, and I'm not afraid to talk about it" badge.
Python, Erlang, Ruby, Java, Perl, bash and C are the ones I've used this week.
 The "I know what a tadpole is" badge.
Because I don't qualify for a badge with a sperm on it.
 The "I'm a scientist who is fundamentally opposed to administrative duties" badge.
Just let me write the code.
 The "experienced with electrical shock" badge. (LEVEL III)
I'm an electronic engineer and spent several years doing backstage work. I have both received and delivered more than my share or electricity.
 The "totally digs highly exothermic reactions" badge.
Self explanatory. *BOOM*
 The "somewhat confused as to what scientific field I actually belong to" badge.
I dabble in a lot of things.
 The "I'm into telescopes astro" badge. (LEVEL I)
I have never owned one, though. When I'm rich I'll remedy this.
 The "statistical linear regression" badge.
I have written software to do this. I don't remember the details, though.
 The "I've set fire to stuff" badge. (LEVEL III)
Self explanatory, really. I even designed a heat engine at one point.
And that's about it. |
|
|
| Python one-liner |
[May. 23rd, 2007|10:21 am] |
Today, I needed to get some information out of my Amazon AWS usage report. (Bandwidth usage, in this case.) I wanted pretty output in gigs (usage is measured and reported in bytes) and I didn't want any of the extraneous stuff. Since AWS helpfully provides a CSV, I wrote a cunning little Python one-liner to extract it:
python -c 'print "\n".join([str(int(line.split(",")[-1].strip())/(1024.0**3)) for line in file("/tmp/report.csv").readlines()[1:]])'
You need to read this from the inside out, since it's a list comprehension. First, it reads all the lines from the csv file and throws out the first (because I don't want the header). Then, it splits each line at the commas and only looks at the last. This is converted to an integer (stripping off whitespace first), divided by the number of bytes in a gig and turned back into a string. These processed lines are collected by the list comprehension, have newlines stuck in between them to make one long string and printed.
0.472050191835
1.29025535937
2.04500017408
2.04324277025
1.82879307121
2.03375558369
0.681352665648 Yay Python! (The Perl people could probably do it in fewer characters, but it would look more like line-noise.) |
|
|
| Set operations in bash |
[Mar. 9th, 2007|02:01 pm] |
This post is some Linux geekery inspired by a problem a coworker solved today.
The problem was that he had a file full of stuff (one item per line) and another file full of partially overlapping stuff and wanted a list of the stuff that appeared in the first file but not the second, which is essentially set difference. This was to be done in bash by preference, as it was part of a longer script and perl/ruby one-liners look ugly in scripts. You may want to take a few seconds to try figure this one out before you look at the explanation below.
cat foo bar bar | sort | uniq -u
Starting at the end, uniq -u outputs only lines that have multiple consecutive copies in the input. Since the lines need to be consecutive, the input needs to be sorted. The cat portion is the trick. We cat bar twice to make sure that it will never contribute a line to the output. Combined with foo, this will give us one copy of any line that appears only in foo, two copies of any line that appears only in bar and three copies of any line that appears in both. There is only one real requirement, and that is that foo contains no duplicates to begin with. This is fairly trivial to arrange and is left as an exercise for the reader.
This is not the only set operation possible, however. You can also do the following:
- Intersection (requires no duplicates in either file): cat foo bar | sort | uniq -d
(Have a look at man uniq for details on the flags it takes.)
- Union (no input restrictions): cat foo bar | sort | uniq
(The sort and uniq are not strictly required here, but they keep the output format the same. Also, the sort | uniq can be replaced with sort -u for a small efficiency gain.)
Complements don't really make much sense since you can use difference to filter out the set you don't want from pretty much everything. Shell scripts seldom need to deal with infinite sets and they'd probably take too long to run anyway...
This post brought to you courtesy of caffeine, day-job problems and mithrandi. |
|
|
| navigation |
| [ |
viewing |
| |
most recent entries |
] |
| |
|
|