ruby #tap and #let

Sometimes you want to do something like #each except operate on the object, not the values. #tap comes close, but it returns the original object. the solution is something like #let but ruby does not have that.

The good news is #instance_exec can do it.

Example: [1,2,3,4,5].instance_exec { reduce(0,:+).fdiv(size) } #=> 3.0

gem-less alternative to auto_link for rails 3.1, 3.2+

Instead of gem install rinku

You can just use something like this in your application helper:

def auto_link(x)
highlight(x, URI.extract(x), :highlighter => '< a href="\1">\1')

Rinku is likely faster however. Also, the ruby stdlib URI’s internal regexp for URIs might not be good enough to catch all URIs, so watch out for that.

If you wanted to detect tags too, and have it link to then perhaps something like this

def auto_link(x)
y = highlight(x, x[/#(\w+)/], :highlighter => link_to("\\1", "/\\1"))
highlight(y, URI.extract(y), :highlighter => link_to("\\1", "\\1"))

More info about highlight can be found in the ActionView helper

The importance of the philosophy behind the software you use

When I choose to use an OS, or a software program, or a programming language, I tend to look at the philosophy that guides the makers and users of the software first. Then I determine if it matches my intended use or purposes.

In my opinion, it’s very important to make sure the philosophy suits the purpose of what you’re using the software for. It results in less headaches and less surprises.

If you look at the philosophy of the maker, you can see how it affects the entire feel and what the software is good for.

For example, the Ruby programming language comes from Matz’s personal philosophy for a programming language that is fun to code in, without any extra steps and with an unusually readable syntax. From that you can tell it’s hella fun to code in, but speed was never a priority. So don’t use it for mission critical stuff unless you plan on replacing bottlenecks with faster solutions.

Another example, Rails, the web development framework built on Ruby, is based on David H.H.’s aesthetics and pragmatic rule breaking approach. When he said “Fuck You” to vendors in his infamous conference speech, I was sold.

Ultimately it comes down to personal choice, and what your priorities are. I chose Ruby & Rails several years ago because both of those philosophies resonated with my priorities.

Sounds pretty straight forward doesn’t it? But you’d be surprised that people often make choices that are completely counter to the philosophy.

The biggest example of people making such a questionable mistake that I can think of off the top of my head is Ubuntu web servers. Ubuntu is very popular, and its original philosophy was to be the “best desktop linux distribution.” However, you see many people choosing to run it as their production web servers.


This seems like a pretty obvious mis-match. In reality, it probably works just fine as a server for many people. But I will never be surprised when others encounter huge headaches in the setup or configuration or debugging of their Ubuntu “web servers.”

The take away message is: Pay attention to the philosophy behind the software, and pick the software that has the philosophy most specialized to the task at hand. You’ll end up with better results in most scenarios. a boon to the nomadic reader

Recently I wanted to buy a book from I had a problem though. I am currently living in Bangkok, Thailand, and I wanted the book NOW. Unfortunately it was an old book with no kindle edition.

I was considering getting it shipped out here, but I thought that the shipping costs were relatively high. I was looking at paying $15 to get the book in 3 to 4 weeks or pay $30 to get the book in 1-2 weeks. Not only that, there was the potential for extra charges from customs. Doing a search, I saw someone once had to pay $15 customs charge on a $15 book from I didn’t want that.

So I had an idea, get it sent to an american book scanner. Save money, and get an e-book out of it too! I quickly found and filled out my order. The book has 330 pages, so I had to pick out 4 sets. I set it for express delivery & amazon service and turned off everything else, including OCR. I can always OCR it myself if need be. All told, it cost $4 to ship it to 1dollarscan, and $16 to get it scanned, and I got it inside of 10 days of placing my scan order & immediately ordering the book from amazon.

I’m happy, I saved anywhere from $10 to $25 and I the book fast, in pdf format, important for a nomad like me!

The scanned book PDF was 210 megabytes in size. They also offer free processing to generate smaller sizes for hand held devices like kindle, iphone, etc. I also tested out the kindle 3 version, and got a 21 megabyte file. The quality is definitely way lower, but it’s still readable.

A vision for the minimalist running nomad

Back in October 2010, Apple upgraded the features of the Macbook Air and suddenly I was confronted with the huge temptation of the fast responsive ultraportable version of my old 2007 MacBook.

The biggest change was the Solid State Drives. The beautiful part is they have no moving parts.

I’ve been doing lots of barefoot running on and off over the last couple years. Imagine running around all the time with an ultraportable laptop. It would be great to be able to run to a coffee store, whip out the macbook air, and get to work.

This would be perfect for a nomad that travels the world and lives out of 1 backpack. With an ultraportable laptop that has SSD, he could run any time he wanted.

Check out Tynan’s blog posts, exactly what I’ve been thinking about
Run, Don’t Walk
Get Rid of Half of Your Stuff
Nomad gear

Comfort Zone & Travel

It seems that when I decide to travel abroad, I suffer from some cognitive dissonance. I have reasons to travel yet I feel bizarre for “abandoning” north america.

My main reasons for travel ultimately comes down to geo-arbitrage and experiencing a new environment.

By geo-arbitrage, I’m talking about enjoying a higher quality of life with a lower cost of living.

For example, I can quite easily live comfortably in the philippines or thailand for $500/mo. In the philippines I once was renting a 4-bedroom house for $225/mo. Getting home cooked meals is cheap too. In Bangkok, it is even easier to get great affordable meals from street vendors.

What kind of life can I have in Canada with an arbitrary budget of say $700/mo? You might ask “Why limit yourself to $700?” but my view is that it is a great opportunity to have most of your income go into savings. Then later on, one can be truly wealthy. Food costs for one person in Canada is easily $250/mo if not more. Renting a tiny suite in an exciting location would likely be $450/mo. That’s already $700. Plus the costs for everything else is higher, entertainment, activities, transportation, clubs, whatever. Life is not fun at all with a such a tight budget.

Comparable, in an exciting city like Bangkok, with many expats, and a totally different culture and language in Thai, lots of opportunities, can enjoy life to the fullest with $700/mo most likely. Why not?!

best airfare site for my needs

Today I figured out skyscanner. I saw it all the time before, but never realized how powerful it was.

This is the formula of power: code goes here!)

You can use sky scanner to find the cheapest flights from a specific airport to anywhere. This is a huge boon if you are 100% flexible in your travel & you have budget requirements.

Another thing that I also figured out is that finding cheap multi-city flights is the ideal thing to do because these flights can later be converted into extended stayovers at the purchase site you end up at (ebooker, vaya, orbitz, whatever). Basically just choose the multi-city option and re-input the flight details, but stick a few days in between. Probably have to play around with different days, but you can usually get at least 2 day stay overs for free or a few bucks more.

12k run

On sunday I ran a 12km marathon in 1 hour and 20 minutes. It feels good to accomplish that. I ran it pretty slow, and I ran the whole thing in water shoes (basically flats).

A couple of people asked me about my shoes so I told them I was representing the barefoot faction.

We have only been running in shoes with lots of cushioning (and even worse, arch support, etc) for 41 years. Ever since the birth of Nike. Before that, the shoes we had were thin and flat – not much different from going barefoot, just enough to keep our feet warm and comfortable.

That is 41 years compared to the million years of upright walking and running that we have behind us. Homo erectus was fully bipedal and existed 1 and a half million years ago.

Interestingly, there is no scientific support for padded heel shoes. Scientific studies haven’t actually been able to show that injury rates are lower with running shoes, in fact, shoes appear to do the reverse – increase injury rates. Yet we all have unconditionally accepted shoes as being absolutely necessary to run in.

I would call it one of the greatest tragedies of humanity.

I am out to prove that running barefoot or in flats is the best and safest method of long distance running. I want to prove to myself that shoes are unnecessary.

It feels incredibly weird to be a barefoot runner amongst hundreds of other runners. It is so weird to go against something that has been deeply accepted, shoes with padded heels. But I do my best to focus on my own results.

New Years Resolution for 2011

I hereby resolve to spend the year of 2011 striving to be fearless.

From now on I will recognize my fears and start facing them head on, no matter how scared shitless I might be. I will refuse to cower in the face of my fears.

Last year I faced some of my fears, but it is time to step it up a notch!

Stupid Chrome Behavior

This is for the following setup:

Chrome (any version up to 7)
Mac OS X (any version up to 10.6+)
SOCKS proxy enabled in OS X System Preferences.

As a matter of rule, I always leave my SOCKS5 proxy enabled. This is because I travel and use wifi all over the place, it’s much more secure to tunnel all my internet usage through a trusted server. I personally use “ssh -D localhost:8118″ from the command line to get that socks proxy.

Anyways, as a ruby on rails web developer it’s common for me to access http://localhost:3000/. Safari works fine. Firefox works fine. Except Chrome.

Chrome insists on always looking up the domain OR _ip address_. That’s right, even if you enter chrome always checks the ip address against DNS. Firefox does the same thing, but Chrome always checks against the SOCKS proxy even for localhost!

Which breaks things.

The fix:

Add ip addresses like to the bypass proxies list in the System Preferences. Also, click the box for the “exclude simple hostnames” option.

I hear that Firefox maintains it’s own bypass list, which is why this behavior doesn’t show up. Chrome doesn’t have this list..