fawk

| No Comments | No TrackBacks

There are a lot of old-school Unix commands that can be strung together to form miniatures programs a solution where one doesn't already exist. Often times, they're great for nothing more than trimming the output from command line programs to make ocular searching easier. awk is one of these great little text processing utilities, though I usually find myself using it in only it's simplest fashion: to print a specific record from a line of input.

Caligula:~$ df -h|awk '{print $2}'
698Gi
298Gi
190Gi

That awk command, '{print $2}', is more than a bit cumbersome to type, so I keyed up a quick function in my .bashrc to make performing this quick operation easier:

Caligula:~$ df -h|fawk 2
698Gi
298Gi
190Gi

And the function:

function fawk {
    first="awk '{print "
    last="}'"
    cmd="${first}$${1}${last}"
    eval $cmd
}

I've written this post before, but things have changed since the 7.04 Feisty Fawn release, so it's worth an update. In recent releases of Ubuntu the Gnome Control Center has made it easy to simply click away the unneeded caps lock key, turning it into whatever you want. I wanted to try KDE 4.2 a few days ago and found no way to turn off the caps lock key. From my previous post, I knew that it's easy to add a line to the xorg.confwhich will turn the caps lock into another control, but when I opened the file on my Ubuntu 8.10 machine, I was surprised to find very little in it:

Section "Files"
EndSection

Section "Module"
    Load  "glx"
EndSection

Section "Monitor"
    Identifier   "Configured Monitor"
EndSection

Section "Device"
    Identifier  "Configured Video Device"
    Driver      "fglrx"
EndSection

Section "Screen"
    Identifier "Default Screen"
    Device     "Configured Video Device"
    Monitor    "Configured Monitor"
    DefaultDepth     24
    SubSection "Display"
        Virtual   1680 1050
    EndSubSection
EndSection

If you come from a long line of Linux use, this is a very odd X config indeed since it lists no input devices, but such is the magic of HAL which takes care of all that for you. The option to turn you caps-lock key into a control is set in the keyboard's InputDevice section. The above-listed stock Ubuntu 8.10 xorg config doesn't have an InputDevice section, nor does it have the associated ServerLayout block. The following can be appended to your /etc/X11/xorg.conf:

Section "InputDevice"
    Identifier  "keyboard"
    Driver      "keyboard"
    Option      "CoreKeyboard"
    Option      "XkbOptions"    "ctrl:nocaps"
EndSection

Section "ServerLayout"
    Identifier  "Default Layout"
    Screen      "Default Screen"
    InputDevice "keyboard"
EndSection

With that, you will now have a caps lock key no matter what window manager or desktop system you use. I love the caps lock as a control because I use vi extensively and make use of ^f & ^b, which move up and down pages, and ^e & ^y that move the buffer's view up and down without moving the cursor. I'm sure emacs users will appreciate this change as well, since they use control alongside 6 or 7 other keys whenever they want to do something.

I have a workstation at my office, drewble, that has a non-routable IP address. Our network is setup such that, even from the VPN, I can't access that machine directly — I have to go through one of our dev servers to get to it. Obviously, having to hop from one machine to another is a bit cumbersome, but as with many thing, this can be alleviated with some simple Unix magic. A simple alias in my .bashrc makes the bouncing simple:

alias drewble="ssh -f -N dev1 -L 9999:drewble.genius.local:22; ssh -D7070 -p 9999 drew@localhost"

The first SSH command in this alias goes to the dev server, dev1, setting up a forward of the local port 9999 to the SSH port, 22, on my workstation, drewble, found via its zeroconf hostname. The -f options causes SSH to background after logging in and -N means that SSH won't run any commands after loggging in; I only care about forwarding ports. The second command utilizes the tunnel setup on port 9999 to get me to the workstation, setting up a dynamic tunnel on port 7070 which can be used as a SOCKS proxy by things like my web browser.

Mac::iTunes::Library

| 2 Comments | 1 TrackBack

Though I use Last.fm it's not a perfect representation of my listening habits. Between the occasional server downtime, not uncommon in the Audioscrobbler days, I wanted to be able to get some accurate statistics about my music library. It's easy to create smart playlists to find the number of songs you have of each genre or by each artist in your library, but much more interesting is to see what you actually listen to the most. There are a number of artist whom I only have a limited collection of, but enjoy quite a lot. DJ Miko being a great example - 10th by number of tracks, but a strong 3rd by playcount. I just can't get enough of those Eurodance beats. Conversely, Scooter is a prolific producer, but a long way from my favorite artist.

Genre-wise, I've got a lot of trance, but apparently end up listening to Ska more. Is that really true? Well, it is by playcount, but I should probably to a listing based upon playcount times song length; Trance tracks tend to be lengthy, especially if you count the numerous DJ mixes I have. By this same token, I'd venture a guess that the average song length of my library, 5 minutes 13 seconds is on the longer end of the spectrum. Finally, the ratio of songs to artists is a quite reflection of whether a library is represented by an encyclopedic collection for each artist (high ratio) or a schizophrenic mix of singles (lower ratio). I have no idea what an absolute scale for this number is, but I'd love to hear results from others.

Also, my library has grown quite a bit:

Number of tracks: 10737
Total size: 85605.68 MB         Average size: 7.97 MB
Total time: 38d 23h 3m 0s       Average time: 5m13s
Ratio of songs/artists: 4.576726342711

Most popular artists, by number of tracks:
        137     ATB
        118     Scooter
        116     blink-182
        115     Armin van Buuren
        111     Paul van Dyk

Most popular artists, by playcount:
        1585    blink-182
        1279    Goldfinger
        873     DJ Miko & Mini Me
        837     Less Than Jake
        753     Big D and the Kids Table

Most popular genres, by number of tracks:
        1627    Trance
        1219    Dance
        1073    Ska
        628     Rock
        583     Vocal Trance

Most popular genres, by playcount:
        8448    Ska
        6334    Dance
        5328    Trance
        2846    Punk
        2723    Rock

It's certainly been a while since I started this project and the module that I spun off of it has been around for a good while. I've compiled the script into a PAR that should run without needing Perl or any modules on any 64 bit Mac OS X machine. From a terminal:

wget http://dinomite.net/2009/01/itunesstats
chmod +x itunesstats
./itunesstats ~/Music/iTunes/iTunes\ Music\ Library.xml 5

If that doesn't work for you, you can simply install Mac::iTunes::Library with CPAN; CPAN might require configuration but, except for mirror selection, the defaults will work:

$ sudo -H cpan -i Mac::iTunes::Library

With the module installed, you can download and run the example script.

Details on the code: The module allows you to parse the iTunes XML library which is generated by iTunes every time the library changes. iTunes itself uses a binary file to manage your music and the XML is only generated as a courtesy. Thus, my module can represent a library and the items within it in full, but I only have a parser for the XML and provide no way of emitting a new XML library. brian d foy has a module that is able to parse the binary iTunes - as long as it's version 4.5. For the uninformed, we're on iTunes 8 these days. Updating that module might be my next project.

For the first time a few months ago I traveled by plane and brought lock picks in my carry on luggage. After having read this article about sneaking lock picks in the extension tubes of rolling luggage, I wondered what would really be required to just sneak picks through. Though flying with lock picks isn't illegal the TSA agents are not known for their accurate knowledge of the rules concerning air travel. I really wanted to have picks at my destination so that I could do a seminar on picking; I didn't want them to be taken away by an overzealous agent.

Lock picks don't have that much mass so I figured if I removed all of normal metal, including my belt, that I'd get through the metal detector OK with the picks in my pocket. I tried this tactic on the trip to my destination and was successful. After removing my belt, I just put my four picks & three torque wrenches in my shirt pocket and waltzed through the metal detector to no notice of the TSA agent. That was easy.

The return trip was equally uneventful, though I used a different method - I simply put my picks into the bag that I put through the X-ray. Again, this was of no interest to the TSA; either they didn't notice or they know what picks are and that it's OK to carry them. I'll assume the former.

Long story short: you can easily sneak a few picks through in your pocket if you have no other metal on your person. Odds are you can get some through the X-ray machine without any hassle, as well.

Why do so many people rave about Amazon's recommendation engine? I bought a Canon 40D from Amazon only a few months ago, have looked at various accessories for that body, and have a Canon lens on my wishlist. Why are they recommending me a Nikon battery?

After years of being cold on the slopes, I think that I've finally gotten the gear to keep myself warm. Through a high of 4 degrees Fahrenheit a few days ago and 16 degree snow with 20+ MPH winds today. I'm sure someone will find this information useful.

I wear a helmet, so hats are out of the question. Instead, I have an Icebreaker Quantum balaclava; in addition to being quite warm, it stays so even when wetted with snow or breath. As for tops, I wear an Under Armour ColdGear mock turtleneck with an Icebreaker Bodyfit 260 TechTop over top of that. I think this combination of a tight-fitting synthetic base layer with very warm merino wool atop is the best way to go. When the weather is very cold, such as the aforementioned bitter or windy days, I wear a Descente Podium vest. I top this all with a Spyder Rival insulated jacket.

My hands have always been a very difficult part, but was the final piece that I solved this year. I'm wearing a pair of Manzella Silkwieght Windstopper gloves, which are just thin, polyester pieces, inside a set of Black Diamond Mercury Mitts which are absolutely wonderful. The mitts are roomy enough that my hands with those liners fit easily, allowing me to quickly pop them out to take pictures, use my phone, or deal with my gear. Polyester for the liners is good because it shed snow when I do pull my hands out of the mitts. The my outer handwear also has insulation that is easily removable, making overnight drying a snap.

On bottom, I wear a single pair of Smartwool socks and a couple of pairs of polyester long underwear. I should really get some wool long underwear, because it's certainly better than polypropylene. Generally, though, I'm doing enough with my legs that I don't have that much problem.

Note on brands: I mention all the brands of things I wear because it makes clear exactly what I'm talking about. Generally, the style of the item is what is important. For example, Smartwool makes tops very similar to the Icebreaker one I mention. I know that North Face makes tops much like the Under Armour ones that I like. As for vests, I very much like the North Face & Mountain Hardwear ones that I have, in addition to the Descente.

Harley Shaiken had a piece on Marketplace yesterday arguing that high labor costs, the sticking point for Senate Republicans concerning last week's bailout, are not a prime reason for the US auto maker's downfall. I don't feel the need to break apart Shaiken's short argument, because he sums it up well in the final sentence, "A superior product, high productivity and high wages pave the road to a healthy economy and a decent society." We can all agree that workers in Detroit have high wages and the indigenous car manufacturers even have good productivity; but a superior product? Not a chance.

The prime reason that Asian cars sell so well in the United States is because they have a superior product at nearly every price point when compared to the US companies. Often features are not what makes domestic cars pale compared to their Korean & Japanese counterparts; usually a general air of cheapness, from bad switchgear and low-grade plastic to unsorted suspension American cars are made to a much tighter budget. The reason? High labor costs at the plants of domestic auto makers, an average of $78 vs. $45 for non-union plants, force those car makers to make up for these costs elsewhere. The only way to compensate for such a large disparity in costs is for the US manufacturers to cut back on the amount of money put into their product, hence the low-quality cars.

Very old Parkour

| No Comments | No TrackBacks

This video clip from a 1977 film Gizmo! shows a 1930s newsreel clip of a man doing Parkour moves, well before such a thing had a name or community. It's incredible to see exactly the same movements being performed 75 years before I had ever imaged doing them. About 20 seconds in he does a wall-run top-out in the exact same fashion I've seen numerous people do on the high box at Primal. Neat.

Discussed previously on the APK Forums here.

Voting Systems

| 1 Comment | No TrackBacks

On the eve of the election, I am thinking about voting systems better than that which is currently employed in United States general elections.

Among single-winner voting systems, the most common is instant-runoff voting and the simplest, making it the most reasonable choice as a replacement for the single-vote system that we currently use. In an instant-runoff election, you fill out a ballot showing the order of preference for the candidates available. When votes are tallied, your number one candidate is used to tally votes; if that candidate did not achieve a majority, then he is eliminated from the election and your second choice is taken. This continues until a candidate has achieved a majority, thereby winning the election.

IRV allows for voters to cast a ballot for a candidate whom they truly believe in without feeling that they are throwing their vote away. This solves the Ralph Nader problem from the 2000 election. Nader was the prime choice for many Americans but his status as a third-party candidate meant that he had no chance of winning the election. Many who might have wanted to vote for Nader instead voted for one of the two major-party candidates, because their vote would otherwise be wasted. The few who did vote for Nader, were then blamed for Al Gore's loss of the election, since they most likely would have voted for the Democratic candidate were it not for the Green Party's presence. Instant-runoff voting keeps third-party candidates from "stealing" votes from the major parties and makes third-parties viable, since voters can feel confident in voting for such candidates.

Another area of voting that is lacking in the United States is the security and integrity of the voting system. There are endless reports of electronic voting machines losing votes, miscounting votes or being tampered with. Creating a system that is both secure and verifiable while at the same time anonymous is not a trivial task but there is a group of people who deal with such odd logic puzzles: cryptographers. After the fiasco of electronic voting machines in the 2004 election, many people spent time thinking about methods for secure, verifiable voting. One of those was Ron Rivest, the R in RSA, who came up with the ThreeBallot voting protocol.

The entire protocol is detailed in Rivest's paper, but the gist of the system is that the voter fills out three ballots which are identical, save for a unique number identifying each. Through some cryptographic logic magic, the ballots are marked such that any single ballot of the triplet does not divulge whom the voter cast their ballot for; because the ballot is unique, however, the voter is given a copy of one of the three to take home. This receipt can later be checked against the ballots that are published so that the voter can verify that their choice was indeed counted. Again, this publishing doesn't divulge information about whom they voted for, despite the fact that all of the information of the election is published, allowing anyone to perform a recount.

See also: Punchscan End-to-end auditable voting systems

Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... 25 Next

Pages

Find recent content on the main index or look in the archives to find all content.