Quite a while since I wrote a post now, I’ve not been sick or anything, but there has been a lot of work abound, and outside work I prioritized sleeping over writing. But now I’m back for the moment, so let’s get down to business
Since last time I’ve come up with new ways of abusing awk, such as having it find the highest value from a command outputting in the following syntax:
\t<characters, integers, fullstop>: <integer>\n
To make it a little more different, the command also spits out a header, as well as an additional newline after the end of output.
I just now, while writing this, came up with a different solution, which doesn’t use awk:
theCommand | grep -v '^[^ \t]\+' | tr -d ' ' | cut -d':' -f2 | sort -r | head -n 1
but what I ended up using was:
theCommand | awk 'BEGIN { highest = 0 } $0 ~ /^[ \t]/ { if ( $2 > highest ) { highest = $2 } } END { print highest }'
In this case, from what I can gather, awk is the more efficient solution. One process versus five.
Update: As Werner points out, the if statement isn’t really necessary (which also makes it possible to cut out the BEGIN statement as well):
theCommand | awk '/^[^ \t]/ && $2 > highest { highest = $2 } END { printf "%d\n", highest }'
Utilities
- ditaa (a.k.a DIagrams Through Ascii Art) makes it easy to generate nice-looking diagram images from… rather nice-looking ASCII diagrams
- docopt, a command-line interface description language, which also seems to support generating the parser for the CLI being described
- Peity for generating different types of charts using jQuery and <canvas>
- Ghost.py interacting with web pages, programmatically
As of late I have been thinking a great deal about backups and the project which seems the most interesting to me is Duplicity.
Random tech stuff
- Shell scripts and exec: This will (hopefully) change the way I script things
- Using external commands in Vim
- Using UNIX as an IDE
- Using ed I have more or less decided that this is the next thing I’m going to learn
- A (simpler) successful Git branching model
- HTTP 451 — Legally restricted
- Select two random (not directly connected) nodes from networkx and Python
- MonkeySort, because humans suck at sorting large lists, but can easily pick the best out of two options presented
- Tron, implemented in 219 bytes, won’t work in Firefox, but serious hackpoints anyway
Other random not-so-techy stuff
- The $4 million complaint call
- The case for a healthier hackathon
- TSA expanding into subways?
- Why privacy matters
- Sending cheaters to cheaters hell, or creating an new (hardcore) game mode?
- DRM continues to hassle legitimate customers…
- Censorship + Internet = Streisand effect
- Apple is just letting people vote with their wallets, sadly…
- While this technology seems rather cool it has some scary privacy implications… good thing one can still write text offline, copy it and paste it wherever it needs to go
- Why software patents suck and coincidentally also why I prefer devices which are not vendor-controlled, where stuff I have put there won’t be deleted unless I want it to happen
- One self is not enough
- Sadly I think this is used way too much, i.e. decide what new law you wish to impose, then come up with something ten times worse, and all of a sudden, the thing you were aiming for sounds reasonable in comparison…
- NSA can’t tell you if they’ve spied on you, because that would voilate your privacy…
- Society sure hasn’t come far…
- Our brains seem to give anecdotes too much clout
What I pass for humour
- A game theoretic approach to the toilet seat problem
- The elusive ANY key…
- Serious and funny at the same time
:wq