-
Do the simplest thing that could possibly work
2010-07-28 23:35:48, by Per
I've been listening to Security now lately, which I like (although I'd like to hear less commercial blahblah on it). When I recommended the podcast to some one (more specifically the Portable dog killer episode), I got the reply that only the last 20 episodes or so came up on iTunes.
Now, on Steve Gibson's Security Now! page, all the episodes are linked, so I thought I'd make a small script to download all the episodes.
First, I got the page locally, so I didn't have to hit the page every time I took the script for a test run:
$ wget http://www.grc.com/securitynow.htm
Then I whipped out the snake and wrote a script
sn.pyfrom BeautifulSoup import BeautifulSoup links = BeautifulSoup(open("securitynow.htm").read()).findAll("a", href=True) for l in links: if l["href"].endswith(".mp3") and not l["href"].endswith("-lq.mp3"): print l['href']This gave me the links to all the mp3's, one per line. I redirected that output to a file, that I then used as input for wget again:
$ python sn.py > snpodcasts.txt $ wget -i snpodcasts.txt
Done...
This took about 20 minutes, so wondering about where my time went and contemplating about the approach I took; there were a couple of things bothering me:
- On my desktop I didn't have BeautifulSoup yet, so I needed to install that first
- When doing one of the first test runs, I had not taken into account that the page also lists the lower quality version, which I didn't needed and certainly didn't want to download too.
- The going back and forth between shell and Vim (wget, coding python, testing python script, running the script and then wget again), although something I do often on larger coding project, felt kinda "fiddly".
Then I realized I just caught myself "doing the first thing that comes to mind" and mistaking that for "doing the simplest thing that could possibly work"; because I immediately saw a possible solution, my mind automatically assumed that that was the simplest thing to do. But, if I had taken a closer look at the problem at hand and a closer look at the page and how the links were formatted, I'd probably come up with following one liner:
$ wget $(python -c 'for i in range(1, 259): print "http://media.grc.com/sn/sn-%03d.mp3" % i')
Now, this might be not as generic as the first solution, but it would've been up & running in maybe half the time.
"Doing the simplest thing that could possibly work" is a programming mantra that has taken quite a while to sink in, and look, it still bites me from time to time.
-
A new desktop
2010-06-13 21:19:39, by Per
It was in the beginning of this week, Monday I believe, so you couldn't get much more "beginninger" even if you tried, that dear-brother-in-law popped by to drop of the desktop machine that I bought from him. Being second-hand, it is certainly not a bleeding edge, blazingly fast, super machine, but then again, I'm not really into that. Manu (the brother in law) is however, so even by today's standards, and considering the price I paid, it's not that bad of a configuration at all:
- Asus P5C mobo
- Intel Quad Core 2.66Mhz
- 4GB DD3 Memory
- 2X 500GB Samsung drives
- Nvidia 8400GTS - 512MB
- Antec case
I'm really stoked about this machine because now I can have both: a linux (Ubuntu 10.04) on my desktop, which I like because of its package management, the (imho) more productive desktop system, the excellent and overwhelming amount of programming tools, and last but not least, the idea that I'm again running a free operating system.
And on the other hand; I can keep the OS X loaded MacBook, which I like because of the hardware support, the looks, but most of all the awesome suspend & resume and the battery life. I have never experienced anything like it on either Windows or Linux. Suspend/resume and battery life were the most compelling reasons for not putting Ubuntu on the laptop and now I don't have to.
The installation went smoothly, the necessary hardware was all recognized, package installation was a breeze (oh
apt-get install, you have no idea how much I've missed you.) and since I have my documents, configurations and code all stored in either Subversion or Git, the machine was quickly configured and ready to go.It's the first desktop I'm using again since I bought my first laptop about 5 years ago, and I'm really enjoying it. No I can't easily take it to bed with me, or anywhere else for that matter. And yes, the full size Logitech keyboard that I've dusted for the occasion needs some getting used to again (typing blog entries helps ;-) ), as does the rather large distance from the keyboard's home row to the mouse on the right hand (with the cursor and numeric pad islands in between). But the large screen, the fact that I'm sitting in a more responsible position (ergonmically speaking), the sheer processing power and the stuff that I like about a linux OS, more than makes up for that.
I went with Ubuntu, the distro that I've been running on my laptops since about 2007 and was surprised for a couple of reasons. The new theme (the aubergine crap (tuutuut) that Fab on the Linux outlaws hates so much), well, I kinda like it, although the terminal background color is a tad too much for my likings.
But what made me cringe is the fact that they have switched the windows buttons (min-/maximize, close) from the right to the left. I have no idea what the Ubuntu UI people where thinking, at all. Personally I've left them there, since I don't want to be confused all the time when switching from my laptop to my desktop and vice versa, but I can only imagine the gigantic feelings of furiousness the average Ubuntu user must have felt when booting his/her freshly installed 10.04 version!Once again, I've become a slightly happier coder, being on my preferred OS.
It feels good to be free. -
Profiling PHP apps on Mac OS X
2010-06-10 22:02:06, by Per
As a reminder to self, but if it helps anybody, great!
Note that these steps where performed on a MacBook5.1, running OS X 10.5.8, Apache 2 with PHP 5.3.
Xdebug
Simplest way to get Xdebug up and running, I think, is to download the Komodo RemotePHP debugging package, extract it somewhere and copy over the relevant xdebug.so file over to something like
/usr/libexec/xdebug.so(for me the file was under the 5.3 directory, because I'm on PHP 5.3, duhu).Next, configure php so that xdebug is used. Add following to php.ini:
[xdebug] zend_extension=/usr/libexec/xdebug.so xdebug.profiler_enable=0 xdebug.profiler_enable_trigger=1 xdebug.profiler_output_dir=/tmp/
For the exact options, visit the xdebug website. For my main setup I keep de profiling trigger based, so by adding to the url I'm testing, the profiling process is triggered. However, if I'm doing a more intense profiling session, I set the?XDEBUG_PROFILE=1xdebug.profiler_enableoption to1, thexdebug.profiler_enable_triggerto0and restart apache.We now have debugging and profiling set up. Xdebug generates cachegrind compatible files, these are text and you can probably read them, but they really need parsing so the data can be presented in a more meaningful way. Now, on Mac, I could use macports to install Kcachegrind, but I really do not want to wait for a couple of hours until all necessary KDE libs have been compiled from source. I could go for Maccallgrind, but not being free (as in both speech and beer), it rubs me the wrong way. And you know what happens if something rubs me the wrong way... hmz, actually you don't and that's probably better ;-)
But, there's Webgrind, which is BSD licensed, yippie!
Webgrind
Installing Webgrind is pretty straightforward: download the zipfile, extract it where it can be served by Apache and basically you're done. If Webgrind cannot find the cachegrind files, double check the
xdebug.profiler_output_dirsetting in php.ini and the$storageDirand$profilerDirinconfig.phpof the Webgrind install.Click around in your application under test, then point your browser to the webgrind app, select a cachegrind file, have a ball... or not... at this point, I really don't care ;-)
-
"It's funny because it's true"
2010-06-01 23:22:09, by Per
Classic Homer Simpson, and ooo so applicable to what Giles Bowkett says in a Seaside overview on Vimeo (around 8 minutes):
DHH has this incredible ability to reinvent the wheel and persuade people that from here on in the wheel is gonna be... CIRCULAR.
While you're at it: check some of the lightbulb jokes, FWIW, the one about bad Ruby programmers made me laugh.
-
Simple TODO lists in Vim
2010-05-29 22:32:51, by Per
I was sitting with M'Bebbi in front of the telly yesterday (Project Runway was on), while a sudden urge to program came over me. I dunno man, maybe Heidi Klum brought it out in me?
In The Pragmatic Programmer it is said that every year or so one needs to take a look at a new programming language. It is also said that you should learn one editor and learn it well. Combine these two things and I was soon firing up Vim to get my feet a little wetter in my beloved editor of choice.
The results are a couple of functions that use Vim regex (substitutions) to manage todo lists. Basically you can place (or remove) a tickbox ([ ]) and then fill it with a V or X to mark a todo as finished or cancelled. You can also fill the tickbox with a SPACE, effectively reopening the todo.
Anyway, I've stuck it my Vim configuration directory. It's nothing fancy, but if you want to take a look, it's up for grabs at Github.
-
RIP Guru
2010-04-20 15:37:02, by Per
... may you be forever lounging...
-
Don't make me do things you can do yourself
2010-03-30 16:10:26, by Per
In light of Steve Krug's excellent book: "Don't make me think"
Having changed jobs, I've got a train commute of about 45-50 minutes (luckily only once or twice a week), time enough to get something done. This can be typing some e-mails, syncing calenders and iPod, doing some developing, whatever... Most of the time, I'm writing some code, be it for work or personal enjoyment.
I'm a web developer, so after running the test suite (if there is one) a couple of times, I tend to take a look at the app in FireFox. So, I open up FireFox and guess what?

Let alone that I would actually go out to the internet to a server/domain named "localhost"... The bloody thing also tells me that I have to go to the file menu, uncheck "Work off line" and then try again. And beneath the message is a bloody button saying "Try again"... I mean COME ON!
I understand that on the train I have no connection to the internet, but when a user tries to connect to "http://localhost", I'd think it is safe to say that it is implied that actually no connection to an external network is needed and having established that, why the hell should the user go through the menu, uncheck something and then press some bloody button... Just connect to "localhost" (it's local, get it?) and be done with it already...
-
Mac whores of the universe, go fuck yourselves.
2010-03-28 13:05:38, by Per
This post has been long overdue. In August of last year, I bought myself a 13 inch MacBook (an alu one, but not a pro). After a couple of months of rather intensive use (it's my main machine, the keyboard is already wearing and I've got a dent in the unicast alu body from dropping my steel iPod classic) these are my findings:
The Bad
Software
Being a web developer and spending most of my time in an editor, shell and browser I'm finding Mac OS X seriously inferior.
- It lacks a decent package manager (and no, macports is not it)
- The way multiple desktops are implemented is just working against me (I want to TAB between windows on the current desktop)
- The terminal sucks, it is way less responsive than the Gnome one and it lacks good cursor navigation
- I want to resize windows in all 4 directions, not just by dragging the right bottom corner, seriously, what is that all about?
- The window controls are on the wrong side, most other GUI's put them on the right, why put them on the left? Just to be different?
Hardware
I'm having a big issue with the keyboard layout; while it is mainly a Belgian AZERTY keyboard, the different placing of braces and angled brackets annoy the crap out of me... Not that I cannot get used to it, because I am, but now when I lay my hands on a normal AZERTY keyboard, it takes a while getting used to. It is just totally unnecessary frustration.
The Good
Mind you, I don't think the mac is a piece of shit, not at all.
- I like the fact that everything just works upon first boot; audio, webcam, multi display, everything
- I like the UI, it's really slick.
- I like the full alu body, the machine just looks sexy and oozes quality.
- I like the screen, it's crisp, clean, has enough contrast and brightness
- I like the keyboard feel
- I like the touch pad
- I luuuuuv the suspend/resume, it's about the only reason that's keeping me from thrashing the OS and slapping on a linux distro.
- Did I already mention that I luuuuuv the suspend/resume? Because I really really do
- The price: Got it for a bit above €800 at Media Markt
There's probably more things that I do or do not like about the Mac, but I think I jotted down the most important ones. The real show stoppers for me are the lack of a good package manager and the handling of multiple desktops, the rest, I probably could live with or without... I think. Anyway, when I got a weekend to spare, I'm slapping on an Ubuntu or something similar.
-
CAPS2CTRL: Addition
2010-03-04 22:41:05, by Per
I want to add a little note to my previous post; if you map
CAPS LOCK toCTRL , do not reverse mapCTRL toCAPS LOCK , your muscle memory needs a while to adapt and sometimes, you will press the originalCTRL and will unintentionally activate caps lock. Also, if someone uses your computer/keyboard, it'll confuse the hell out of 'm. Just letCTRL beCTRL . -
Productivity tip of the week: make caps another control
2010-02-18 23:59:09, by Per
I just recently subscribed to the Fosscast video podcast and came across the episode about remapping the CAPS LOCK key. Although I'm finding it quite finger-wrecking to press CTRL on most keyboards, I never tried remapping CAPS LOCK to CTRL, basically because I'm scared; Since I heavily depend on my ability to handle the keyboard with a certain efficiency (and flair, but that's just a personal requirement), I'm not too keen about having its layout changed. That said, I have to admit that it seems to be turning out quite nicely. I only remapped CAPS LOCK this Monday, and although it is true that my finger muscle memory needs to adapt, I can already feel that it will turn out for the better.
Recommended.- 2010-03-04 Updated with a little note.