christopher.lord.ac

christopher.lord.ac

Christopher Lord  //  I work on compilers for a major corporation, specialized in computer languages and the parsing and optimization thereof. In my spare cycles I hack on Haskell, Ruby, and Objective C. Outside of programming, I am an outdoorsman, a skilled photographer, a student of typography and design, and a patient, better driver.

Dec 2 / 4:09pm

Fractions in Ruby

For a cooking website I recently worked on, I needed to display decimal floating point numbers as fractions. I needed to come up with the fraction closest to what the user typed. For example, 0.33 should resolve to ⅓. When I googled for a solution, most of the code I found was slow, buggy, and too precise (returning 33/100 for the above example.)

I decided to widen my search to C, and found a piece of code on Stack Overflow written by David Eppstein in 1993. It uses the theory of continued fractions to approach the correct value, but stops when the denominator reaches some value. 

The limitation of such an algorithm is that we can't choose to leave out unnatural denominators (that's a topic for some future post: why don't people like to use 7 as a denominator?). 

Anyway, I ended up wrapping up Eppstein's code in a Ruby gem entitled "fraction" and throwing it up on Gemcutter in case anyone needs similar functionality. Using this gem is easy:
require 'fraction'
num, den = 0.33.fraction   # num==1, den==3

# You can also get the error
num,den,err = 0.33.fraction   #=> [1, 3, -0.0033333333333333]

# you can choose a different maximum denominator than the default value of 10:
num, den = 0.51.fraction(100) #[51, 100, 0.0]

You can get fraction from gemcutter

Loading mentions Retweet
Filed under  //  ruby  

Comments (1)

Oct 28 / 6:25am

Want 50Mbps Internet in your town? Threaten to roll out your own

ISPs may not act for years on local complaints about slow Internet—but when a town rolls out its own solution, it's amazing how fast the incumbents can deploy fiber, cut prices, and run to the legislature.

Fantastic! It looks like the "digital divide" is reversing itself in dramatic fashion. Small towns are getting exponentially better internet service than people in the big cities.

Internet should be a service with some baseline quality expectations, and that the only way to provide this (especially in the markets with few incumbent players, like Toronto) is to provide some baseline of competition that raises the game out of the mud of deep packet inspection and excessive overage charges.

Loading mentions Retweet
Filed under  //  competition   government   internet  

Comments (0)

Oct 22 / 6:08pm

Our Campfire

One of our many fires this year, but one of my faves.

Loading mentions Retweet
Filed under  //  camping   video  

Comments (0)

Oct 13 / 4:37am

U.K. Press not Permitted to Report on Activities of Government

The Guardian has been prevented from reporting parliamentary proceedings on legal grounds which appear to call into question privileges guaranteeing free speech established under the 1688 Bill of Rights.

Today's published Commons order papers contain a question to be answered by a minister later this week. The Guardian is prevented from identifying the MP who has asked the question, what the question is, which minister might answer it, or where the question is to be found.

So what's this all about? A British company is dumping toxic waste in Africa. Not just any company either, Trafigura. It's one of those commodity companies that is raping the world for profit.

A boat chartered by the company, the Probo Koala, was caught dumping 528,000 litres of extremely alkaline waste off the Ivory Coast. The Guardian obtained internal Trafigura emails which are claimed to show the company knew the crap was toxic, but was dumping anyway. Now the Trafigura is going sue-happy with the help of their retained legal firm Carter-Ruck. They're trying to prevent this news from breaking, but the Internet is aware, now.

Right now we don't know why the British Parliament is blocking the next part of this story from breaking.
Loading mentions Retweet
Filed under  //  evil   government   oil  

Comments (0)

Oct 8 / 4:39am

MacRuby » MacRuby 0.5 beta 1

The new MacRuby 0.5 runtime is built upon LLVM, a compiler infrastructure also sponsored by Apple. Thanks to LLVM, MacRuby is able to transform the Ruby abstract syntax tree (AST) from the parser directly into highly optimized machine code. MacRuby supports both Just in Time (JIT) and Ahead of Time (AOT) compilation. The JIT mode will compile down the code at runtime, and the AOT mode will allow you to save on disk the compilation result. AOT compilation makes MacRuby a true Ruby compiler.

I'm excited about the prospect of building cocoa apps in Ruby, and compiling everything down to objects. What's better than that? Well, they've fixed the concurrent performance of Ruby by sharding the global interpreter lock, and they threw in GCD for good measure. I believe developments like this herald the end of C/C++ hegemony. At some point in the near future, this will be the default method of building apps on OS X.

Loading mentions Retweet
Filed under  //  os x   ruby  

Comments (0)

Oct 7 / 6:51am

Are Humans Bad at Concurrency?

I hear it all the time. Humans are bad at parallelism and concurrency. "It's just hard," they say. I say that's crap.

In fact, those people have it all backwards. Humans are immensely good at concurrent thought, and really bad at sequential thought.


Consider driving. Your brain is processing millions of things in an out-of-order manner, and producing continuous motions in your hands and feet that guide the car so perfectly that few would be surprised to hear of someone who has driven for a lifetime without a major accident. Our brain can learn this task!

Same deal with many concurrent activities, like having a conversation, or playing sports, or listening to music, writing, thinking about the future, or fixing the fridge. In every case, we set our massively parallel architecture on many problems simultaneously, and then integrate a solution in real time without deadlocks or timeouts. Not only can we learn these things, but we can excel at them, once learned. 

But we humans have a corresponding weakness for sequential thought. We find it very hard to write a piece of sequential software that lasts more than a week without crashing hard or suffering from a major design flaw. We need to be taught for decades in the most advanced institutions to think sequentially and logically. Only the most elite of us ever manage to produce something that others would actually pay for, and even then we may solve a different problem for people than the one we set out to solve. Watch Evan Williams' talk at TED embedded below for an example of how we can invent technology that gets used in non-expected ways.


Then we try to make people trained in sequential thought solve parallel problems, and they come up with steamy piles of tangled mess, full of deadlocks, races, and side-effects.

Our default state is concurrent thought. We've all been trained to think otherwise, by our computers, languages, and education. We're hard on the poor folks who were carefully trained as sequentialists when they fail to make a parallel problem easy on sequential machines.

By day, I work on a compiler for sequential source-code, but my personal long-term goal is to create a compiler for a language that can form the kernel for a new school of thought separate from the sequentialist mode of thought. As hardware evolves, it will only become more like our own brains, and less like calculators and simple programmable machines.
Loading mentions Retweet
Filed under  //  concurrency  

Comments (0)

Oct 6 / 5:19am

The Demise of the Dollar

In a graphic illustration of the new world order, Arab states have launched secret moves with China, Russia and France to stop using the US currency for oil trading

This looks like the first step towards a pan-asian economic bloc, much like the eurozone. This new denomination would be a formidable competitor for the Euro and the Dollar.

Loading mentions Retweet
Filed under  //  economy  

Comments (0)

Oct 1 / 3:31pm

Excreted Tamiflu Found In Rivers

Concerns are now building that birds, which are natural influenza carriers, are being exposed to waterborne residues of Tamiflu’s active form and might develop and spread drug-resistant strains of seasonal and avian flu.

We'll probably end up causing vastly more damage with designer flu drugs than if we just let our immune systems operate naturally like all the other animals do.

Loading mentions Retweet
Filed under  //  biology   evil  

Comments (0)

Sep 30 / 7:19am

Classic '59 in head-on with '09 Malibu

Holy crap, that little car pulverizes the 59.

Loading mentions Retweet
Filed under  //  video  

Comments (0)

Sep 27 / 7:45am

Timescapes Timelapse: Learning to Fly

This is stunning work, be sure to watch in HD if you can. There is even a 1080p version for those with the computer to handle it.

They seem to be using motion control along with a plain old 5D MkII to get this done.

Loading mentions Retweet
Filed under  //  video  

Comments (0)