A human way to define regular expressions?

Posted September 05, 2013

Dear lord, I hope no one is actually using this in production.

pattern = Hexpress.new.
  maybe { words.with(".") }.
  find { matching { [word, "-"] }.multiple }.
  either("com", "org").
pattern.to_r #=> /^http(?:s)?:\/\/(?:(?:\w)+\.)?([\w\-]+)\.(?:com|org)(?:\/)?$/

via Hexpress by krainboltgreene.

How Poverty Taxes the Brain

Posted August 30, 2013

Researchers publishing some groundbreaking findings today in the journal Science have concluded that poverty imposes such a massive cognitive load on the poor that they have little bandwidth left over to do many of the things that might lift them out of poverty – like go to night school, or search for a new job, or even remember to pay bills on time.

via How Poverty Taxes the Brain – Emily Badger – The Atlantic Cities.

Resetting the chronograph on the Tissot PRC 200

Posted November 04, 2012

The large seconds hand (#6 in the diagram above) on my watch somehow got screwed up; when resetting the chronograph, it would always rest on 56 instead of zero. Apparently fixing this is an undocumented feature, though really quite easy to do.

Simply pull out the crown (#12) to the second position as if setting the date. Now, when you press the reset button (#11) the seconds hand will advance by one. Just keep pressing it until you reach zero and you’re all set!

How to fix wget certificate issues

Posted June 12, 2012

If you’ve ever run into this annoying message before:

$ wget https://raw.github.com/bagder/curl/master/lib/mk-ca-bundle.pl
--2012-06-12 14:42:46--  https://raw.github.com/bagder/curl/master/lib/mk-ca-bundle.pl
Resolving raw.github.com...
Connecting to raw.github.com||:443... connected.
ERROR: cannot verify raw.github.com's certificate, issued by `/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance CA-3':
  Unable to locally verify the issuer's authority.
To connect to raw.github.com insecurely, use `--no-check-certificate'.

There’s actually an easy fix!

You may want to run


occasionally to keep things up to date as well.

Profiling Java programs on OS X

Posted May 18, 2011

Sounds easy, doesn’t it? Well it actually is quite simple but the error messages along the way can really trip you up!

My first attempt at profiling a bit of code was to use the full-boat Eclipse stack: Eclipse Test & Performance Tools Platform Project! Well, what they don’t tell you anywhere on the project page is that it’s only supported on Windows and Linux. A Mac port was started sometime around 2004 and never completed. Yeah, it’s been that long!

And so this brings us to Apple’s Shark: an extremely barebones, no-frills profiler, but, what the heck, it’s free. For the basics on using this tool with your Java app, this great post has all the details. There’s just one catch: 64-bit support. There is none. If you’re on a 64-bit stack and you try to run it, you’ll see something like the following:

$ java -agentlib:Shark -cp foo.jar com.foo.Bar
Error occurred during initialization of VM
Could not find agent library: libShark.jnilib (searched /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries:/System/Library/Java/Extensions:/Library/Java/Extensions:.)

Er, what? Now let’s see here…

$ ls -al /System/Library/Java/Extensions/libShark.jnilib 
-rwxr-xr-x 1 root wheel 50352 Oct 24  2010 /System/Library/Java/Extensions/libShark.jnilib

Well, that’s odd. But it said it looked there, right?! Well, as it turns out, the Shark JNI library only supports 32-bit JVMs. So finally, we arrive at the following:

$ java -d32 -agentlib:Shark -cp foo.jar com.foo.Bar
2011-05-18 23:05:20.756 java[84473:20f] Shark for Java enabled...

Great sucess! And now, back to work, just a little less sane…

Compiling Q4M on OS X

Posted May 11, 2011

I recently compiled Q4M on my Mac and I’m documenting it here now because it proved to be somewhat painful so hopefully you’ll avoid a bit of grief by reading this.

First off, you need MySQL Server. I’ve been using MacPorts for some time now, so this is installed via ports. Unfortunately, it seems to be a pretty barebones config so I had to create a custom variant to add the necessary --with-fast-mutexes option. You can grab my modified Portfile from github. Just clone it into some directory and then add that path into /opt/local/etc/macports/sources.conf before the rsync line. Once you have that, go ahead and reinstall MySQL:

$ sudo port install mysql5 +fast_mutexes

Q4M also requires access to the MySQL sources, so let’s get those unpacked:

$ cd /tmp
$ tar -xzf /opt/local/var/macports/distfiles/mysql5/mysql-5.1.57.tar.gz

Once that’s done, follow these steps to get Q4M compiled:

$ cd /opt/local/include
$ sudo ln -s mysql5/mysql 
$ ./configure --with-mysql=/tmp/mysql-5.1.57 \
$ CPATH=/opt/local/include/mysql \
   LIBRARY_PATH=/opt/local/lib/mysql5/mysql \
$ sudo mv /opt/local/lib/libqueue_engine.* \
# Final step, tell mysql to install the engine
$ mysql -uroot < support-files/install.sql

If after all that you’re still having problems, maybe you’ll have better luck with these Japanese instructions.

Getting things done – DDG style

Posted February 17, 2011

I have no idea how Gabriel ever gets anything done, considering that he’s constantly responding to emails, tweets, forum posts, comments on various sites and IRC — just to name a few!

Here’s a typical exchange from earlier today when I reported a poorly performing query on DDG:

I used to be like that when I was at Operative but I don’t think I was anywhere near as productive as him.

Relaunching lunchomizer.com

Posted February 12, 2011

I spent a bunch of time the last couple of days sprucing up a few of my personal projects. Today was mostly spent on the lunchomizer, which gives you random suggestions for lunch, based on your location. It still only works for Midtown Manhattan since the locations all come from Midtown Lunch and that’s also the neighborhood where I happen to work.

The biggest change today was fixing the HTML5 location support and a much better mobile experience via a separate Rails layout tailored for small screens. All in all, it was pretty easy, but one thing that surprised me was a noticeable lack of a de facto standard library for doing mobile, or really any, browser detection. I ended up using a gem called Nomadic and that worked well with the following controller code:

class LunchController < ApplicationController
    layout :choose_layout
    # use mobile layout for mobile clients (using browser detection)
    def choose_layout
        Nomadic.mobile?(request.env) ? "mobile" : "default"

A fairly simplistic solution, but perfect for this app which has only a single controller and a single view :)

And for the curious, the full source is available on github. Fork away!

Creepy voicemail

Posted February 11, 2011

I got this creepy voicemail today on an unused Vonage number that I have:

Vonage transcription: “Good morning and good morning and good more and then I’m. I’m alone. So in the shower. I am gonna be more than any card board boat races in my dreams. Swimming in the lake trip the water”

PS. this is just an excuse for me try out the new HTML5 <audio> tag, which apparently doesn’t work in Firefox 3.6.x.

Stupid Windows Firewall

Posted January 30, 2011

So it turns out that Windows Firewall, even in Windows 2008, still can’t accept a range of ports, either in the UI or via command line, most commonly when setting up PASV FTP transfers. The common workaround is to create one entry per port in your range like so:

C:> FOR /L %I IN (60000,1,60200) DO netsh firewall add portopening TCP %I "Passive FTP"%I

While this does work, it’s slightly annoying that you have to create 200 individual entries in your config. My slightly better workaround is to just stick every port into the text entry field using this simple ruby helper:

puts (60000..60200).to_a.join(",")

You can run this either in IRB or directly on the command line using the following command:

$ ruby -e 'puts (60000..60200).to_a.join(",")'

This is great if your workstation has ruby on it, but sucks otherwise. So use this javascript version right here instead!