Sometimes it’s really useful to prepend a timestamp to every output line of a command. This can be done fairly easily:

$command | \
perl -pe '@now=localtime();printf "%04d-%02d-%02dT%02d:%02d:%02d ",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0];'

The perl command reads in every line, prints the current time in the default format (or in whatever format you specify), followed by the read line.

When hosting multiple sites on a single IP, HTTP1.1 has the necessary items on board to route the request to the correct site. This works because an HTTP 1.1 request includes a Host: header, which indicates to the server which site the client wishes to access.

When using SSL-secured connections, this doesn’t work anymore. The problem is similar to the situation in HTTP1.0: The server needs to know to which SSL-host the connection is addressed. SNI introduces a similar solution: It specifies an extension to the SSL negotiation to indicate which server the client wishes to access.

Continue reading ‘SSL vhosts with Apache’ »

When one is looking around to buy real-estate, loans is something unavoidable for the majority of us. Calculating loans (dutch link) is not black magic, as some banks like you to believe. Below is a JavaScript loan calculator to calculate the missing parameter from the rest. Some calculations can’t be done in one-shot, but need to be resolved iteratively. These are marked “(slow)”. On a descent computer however, these will still run in well under a second.
Continue reading ‘Calculating loans’ »

I sometimes pipe a command to less to study it’s output. If it’s interesting enough, I re-run the command and redirect the output to file. This approach has some limitations: the command is run twice, possibly with different output.

Obviously, I should use tee to send the output to both less and the file, but I regularly forget this. That where this hint comes in: you can save the current less-buffer to file!

In short, to save the buffer that is being displayed by a session of `less’, use its pipe-to-shell-command capability by scrolling to the top of the file and press `|’ followed by `$’ as well as entering `tee DESTINATION_FILE’ when prompted for the shell command.

In Belgium, there are 2 major ISPs: Telenet and Belgacom (Skynet). None of them allows you to run servers on your home DSL connection, but only Telenet enforced this by simply blocking all incoming TCP requests on the low ports.

I regularly connect to my home server over SSH from all over the world to access my files, mail, photos, …. Since not every network I encounter allows outgoing 22/TCP connections, I also listen on 80/TCP and 443/TCP for SSH connections. This setting allowed me to connect home from pretty much every network.

However, since somewhere this weekend, Belgacom started to filter incomming connections. My last successful attempt was around 2009-10-31T00:10+0100. When trying this again today around 16:00+0100, the connection was filtered. Contrary to Telenet, Belgacom has the decency to reply with an “ICMP Administratively Prohibited” message. A quick port-scan showed that the following ports are being filtered:

  • 23/tcp (telnet)
  • 80/tcp (http)
  • 443/tcp (https)
  • 992/tcp (telnets)
  • 8023/tcp (unknown)
  • 8085/tcp (unknown)
  • 8443/tcp (https-alt)

Connecting to home has just become more difficult… Guess I’ll start using IP over DNS

Update 2009-11-03

Found another blog describing this issue (in Dutch). Rumor has it that Belgacom will offer an opt-out of this filtering.

Update 2009-11-11

The filtering of port 23, 80 and 443 can be disabled by surfing to the Belgacom e-service site and opting for “Basic Security” under “mijn internet – mijn opties”.

Fifefox has a very convenient auto-complete function when filling in forms and logins. Very convenient, until you somehow manage to mistype one of the fields (obviously, you never ever mistype, but some people do…). This mistake haunted me for long enough to get me motivated to solve it.

Apparently, the solution is very straightforward: just highlight the “wrong” value in the drop-down and hit Shift+delete to get rid of it.

Usually you don’t want to slow down your network connection deliberately. When testing networking applications, it might come in handy to simulate a worse network than you are actually on. This way you can simulate a 3G connection while actually running over WiFi.

Up until now, I used a Linux-box with netem and/or htb in the Queueing schedulers. Turns out that MacOSX can do most of this as well, using FreeBSD‘s ipfw pipes. Throtteling a single task only takes 2 commands:

$ sudo ipfw pipe 1 config bw 256kbit/s
$ sudo ipfw add pipe 1 dst-ip 192.0.2.1 dst-port 80
33400 pipe 1 ip from any to any dst-ip 192.0.2.1 dst-port 80

$ sudo ipfw list
00100 pipe 1 ip from any to dst-ip 192.0.2.1 dst-port 80
65535 allow ip from any to any
$ sudo ipfw pipe list
00001:   256 kbit/s    0 ms   50 sl. 1 queues (1 buckets) droptail
 mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp

$ # do whatever you want

$ sudo ipfw del 00100
$ sudo ipfw pipe del 00001

Google is my favorite search engine; I use Maps regularly and enjoy Earth as well. I am however concerned about privacy using all these cloud-services. Privacy has a lot of different meanings. Here I’m talking about the control meaning: I want to be in control over my stuff, being it my computer, my mails or my documents.

My concert just got another boost when Growl notified me that a new volume was mounted. I was surprised, since I was laying back, watching a movie… The volume mounted was “GoogleSoftwareUpdate-1.0.6.1054”.

I do have Google Earth installed on my machine, but don’t remember asking it to update itself, definitely not when it’s not even running!

After some digging around, I found the dmg hiding in ~/Library/Caches/com.google.UpdateEngine.Framework.501/Downloads/com.google.Keystone.dmg. Apparently, I’m not the only one who noticed this. This updating seemed to be launched from launchd and can be disabled by removing or disabling the plist-file:

Disabling the startup item can be done by deleting the file ~/Library/LaunchAgents/com.google.keystone.agent.plist or adding a new “Disabled” property to it (in case you want to keep the file):

Disabled

x264 is an open source h.264 encoder. Since r1177 it includes a preset system. The presets give an easy way to balance quality vs encoding speed, ranging from placebo (highest quality) to ultrafast (lowest quality).

I wanted to get an idea what kind of quality/time gains could be archived with these settings. Usually the first steps of extra quality are barely noticeable in encoding time, while the last bits of quality cost significantly more. To verify this statement and to quantify it, I encoded 2 video sequences at 2 resolutions using all 9 available presets. I used PSNR as metric. I’d be the first to admit that PSNR does not correspond to quality, but it correlates reasonably well.

Continue reading ‘x264 presets’ »

The internet is filled with guides and howto’s for getting video on you iPhone. The specs specify the iPhone to support h.264, baseline profile, level 3.0. Translated this means:

  • No B-frames
  • No CABAC
  • No weighted predictions
  • No 8×8 DCT
  • Max resolution around 640×640 (technically 1620 MacroBlocks, 16×16 each)
  • Max 25fps at that resolution (technically 40500 MacroBlocks per second)
  • Max 10Mbps

The iPhone imposes some extra limitations:

  • Max 640×480, 30fps
  • Max 2.5Mbps

Most guides on the internet additionally force the number of reference frames down to 1 (ffmpeg‘s -refs parameter), although I could no find any specsheet imposing this limit. So I decided to test this.

Continue reading ‘h264 limits for iPhone’ »