Archive for the ‘Hacking’ category

My code sucks.

August 2nd, 2010

Cha­sing a link via Twit­ter, I recently read Your code sucks. Having gone over a lot of other people’s code mys­elf, and wri­t­ing code for long enough to have a good history of my own work to go over, it reso­na­ted with me.

I recently had the mis­plea­sure of debug­ging a piece of code that I wrote almost ten years ago. It was, in many ways, pain­ful to read. Alt­hough I still use the same lan­guage as back then, things have way evol­ved: The lan­guage, for one. Deve­lop­ment tools. (Well, not mine: I still use Emacs.) But most of all: My know­ledge and my men­tal hori­zon in pro­gramming. I’ve looked at various other things to enrich my skill set, brin­ging to my own coding hab­its tools that work well in other lan­gua­ges. I also got to under­stand the tools I use bet­ter (espe­cially data­base tools — those are so rich, and so few tools ever really use them). So, with that expe­ri­ence in mind: My code does suck. But I much pre­fer some­thing that I wrote ten years ago to be pain­ful to read, because it means that I have lear­ned a lot. Even though I feel great satis­fac­tion with the things I write today, I am sure that in ano­ther ten years time, I will look back at todays work and feel a slight sen­sa­tion of being asha­med of what I did.

And this hum­bles me in rea­ding other people’s code. It does not hurt to assume com­pe­tency in others; they may have dif­fe­rent rou­tes they take in sol­ving pro­blems. But if one gets to think like they do, under­stand why they wrote the code the way that they did, that cer­tainly may lead to your taking away some­thing for yourself.

Now, if only ever­yone adhe­red to K&R inden­ta­tion, I could read all the other people’s stuff so much more easily …

PDO vs PEAR DB

October 20th, 2005

For a pro­ject that we are cur­rently imple­men­ting, we’ve asked our­sel­ves what the best way to access the data­base would be. So far, a num­ber of our pro­jects had been rea­li­zed with Pear DB, and that was mostly okay. The cur­rent pro­ject needs to be resonsive even under high ser­ver load, so we try to cut away all the slack we can. So we did a few benchmarks.

Wow.

PDO, in cer­tain cases, is up to 4 times as fast as Pear DB.

Lesen im Google-Satz

September 18th, 2004

Inters­san­ter Arti­kel, Google als Wahlprognose-Werkzeug zu benut­zen: Anhand einer Liste von pas­sen­den Sät­zen und Zäh­len von Links ver­sucht der Autor eine Pro­gnose für Novem­ber: The Salt­wa­ter­Pizza Blog: Accor­ding to Google, Bush will beat Kerry in November

Backups

August 19th, 2004

In the office, we cur­rently have about 120gb of disk that need regu­lar back­ups. We wan­ted to have a solu­tion that enab­les us to store off­site copies easily and wasn’t too expen­sive. Tapes were out for hand­ling rea­sons — those dri­ves that we were wil­ling to afford would have meant a sys­tem of casca­ded incre­men­tal back­ups, making res­to­ra­tion of sin­gle files a tape-shuffling issue. DVDs don’t hold enough data and their sto­rage times are not yet fully under­s­tood, so that didn’t quite sound so prac­tical, either.

In the end, we deci­ded to out­fit one of the older machi­nes around (a Pen­tium II) with removable hard disks (nor­mal Wes­tern Digi­tal 160 GB dri­ves, fit­ted into run-of-the-mill alu­mi­nium mobile racks). We have two dri­ves fit­ted into a car­riage, so there’s always one at home and one in the machine. During the day, the appro­priate machi­nes copy their data onto that one volume over the net­work and I can take along the disk in the eve­ning, brin­ging the other one next morning.

Most of our machi­nes run NetBSD so I’ll just quickly run down the very basic con­fi­gu­ra­tion, we have here, but it should also work with many other unix-like ope­ra­ting sys­tems. Ope­ra­ting sys­tem and all esen­tial stuff is on a disk that always remains in the backup machine, the backup volume is a drive off the secon­dary IDE controller.

The machine is only powered on when the disk is in, so there’s no cho­king on mis­sing disks — this could be avo­ided by using a hotswap-enabled IDE con­trol­ler, but cur­rently, we don’t have that need. As soon as the disk goes in in the morning, the machine is powered up, boots and sha­res the backup volume via NFS. The other machi­nes (all run­ning NetBSD) have that volume in their auto­moun­ter. Scripts are star­ted that use dump(8) to copy their appro­priate sli­ces onto the backup drive. As soon as they’re all finis­hed, the machine powers down again, wait­ing for the drive to be taken out.

And that’s all there is to it!

Price of the machine: prac­tically not­hing, we had that alre­ady. We even had an empty 4U 19″ enclo­sure, so it’s gone into the machine rack.
Price of the drive enclo­sures: 25 € each, making it 50 €
Price of the hard disks we’re using today: star­ting from 80 €
That makes our con­fi­gu­ra­tion total 210 €. Not bad for 160 GB of backup storage.