Wishful Coding

Didn't you ever wish your
computer understood you?

Vacuum Balloon

You know these helium balloons? They float because helium is lighter, less dense then air. You know what is even lighter than air? No air at all!

I came across the idea on this website, where he notes

I haven’t done any math, but I assume this isn’t feasible at the present time.

I have done some math, or rather, asked Wolfram Alpha.

So, first of all, how heavy is a cubic meter of air anyaway?

weight of 1 cubic meter air

Ok, so our balloon can weigh just over a kilo and still float. But what is the surface area of a balloon of that size?

surface area of a sphere of 1 cubic meter volume

Almost five square meter. So with one kilo of matter, we need to make a balloon of nearly 5 square meter surface area.

volume of 1280 g Al / 4.836 square meter

Aww, not looking good. If we use aluminum1, we can make a shell of a tenth of a millimeter thick. This shell will have to resist 1 bar, which equals 10 newton per square centimeter.

pressure vessel formula

I just picked this up from Wikipedia, but presumably this means the stress on the shell will be 3162 newton per square millimeter.

Now, remember that this is a vacuum, so while a pressurized balloon retains it shape because of the pressure, the biggest problem with our vacuum balloon is the buckling force.

The smallest dent, a gust of wind, or even gravity itself, will cause the balloon to implode. I asked my dad2, and he asked his engineer, how to calculate this force. Third order magic.

  1. We should be using carbon or some composite probably, but it doesn’t really get much beyond 1mm anyway. 

  2. He’s an architect. 

Google Reader on Kindle

I recently bought a Kindle, and I love it! It takes some effort to convert scanned PDF books, but other than that, you just email stuff to Amazon, and it gets delivered.

For long articles, I found that Instapaper has a ‘Read Later’ bookmarklet, that can be configured to send a digest to my Kindle.

The only hard part was Google Reader, so I thought I’d share that with you. Reader has a ‘Send To’ feature that can send articles to Kindle, but you have to go trough all the articles manually.

We’ll have to involve an extra step, called Instascriber. Instascriber lets you automatically send up to three feeds to Instapaper. Not enough for all my feeds, but luckily Reader has an RSS feed hidden deep down.

The broad approach is to collect your feeds in a public place in Google reader, so you can put the RSS feed in Instascriber, which submits them to Instapaper, which in turn emails them to Amazon, which then finally delivers the issue on my Kindle.

Finding a public RSS feed in Reader is a bit tricky. Information I found about public folders and tags seemed outdated, with the new interface. What you need to do is, go to ‘Browse for stuff’, and create a bundle there.

image of google reader

When you’re done, you need to figure out how to get the feed. I did this by clicking ‘Add a link’, to get to the public page. Depending on your browser, you might already see the RSS icon there. For FireFox, it can be found by pressing CMD+I and going to the ‘Feeds’ tab.

For reference, this is what my feed looks like http://www.google.com/reader/public/atom/user%2F09723460687514136094%2Fbundle%2Fkindle

From here on, it’s standard form-filling and do-as-you-are-told business.

First register at Instapaper, and set up Kindle delivery according to their instructions

Finally, register at Instascriber, enter the Reader feed, and enjoy reading!

Clojure Wiki Gitorial

At the last Amsterdam Clojurians meetup, I gave a presentation with Hubert Iwaniuk, in which I wrote a wiki in 15 minutes, and Hubert explained what I was doing.

Unfortunately no video is available, but I made a Gitorial out of it to show you what I did. Typos included.

commit 9d2f91089dadbe795a16da9d84cb0da33cea9a37

Welcome to this gitorial. I just created an empty Leiningen project with lein new wiki and initiated git with git init

commit e2156be6cbfc421e384ebb016699497501395131

I’m using Ring for serving my application, and Moustache for routing.

commit 1898d45e54d1ae6045742f8e5db3b8fbc1fb7141

I defined a router that will at this point match an empty address and return “hello world”. The -main function can be run with lein run -m wiki.core.

Browsing to http://localhost:8080/ now should display “hello world”.

commit 5e68a78f30586ad5313072201df25e5b1eea76ac

A lot is going on here, form top to bottom:

I imported some Ring middleware. These modify the request and response on the fly. Note that wrap-reload and wrap-stacktrace are for debuging only.

I added the middleware to the Moustache app.

I added routes. The first route matches and WikiLink and binds it to title. The second one redirects all other links to the MainPage.

The #’ syntax is for getting the var instead of the value, to make reloading work.

At this point, visiting the same url should redirect to /MainPage and display “hello tester”

Changing this text does not require a server restart, so we can keep it running from now on.

commit ae78c9d640420d0154b22c66df581fa684b8aa48

I lied, to add a new dependency, you need to restart the server.

Hiccup is a DSL for generating HTML.

I defined a HTML template and a function for showing it that takes a request and a title.

Note that I used the underscore to denote we’re not using the request.

Delegate is a HOF that returns a function with the title alreadu supplied. Moustache supplies the request.

Try visiting /FooBar now.

commit cd24f552f7eefb470ac7b4357d01486e0fc9c888

I added Clutch as a dependency. Clutch is a library for CouchDB.

Install CouchDB and use Futon to create a wiki database and insert a “MainPage” document with a “content” key.

I defined my own Ring middleware that takes a handler and returns another function that calls the old handler in the context of our database.

The show function now gets a document from the database and passes its content to page.

commit f0c831708f397137b9aadf397376de2202f5cd60

You can now edit and create pages.

Page now takes a revision, which is used in the web form to update.

The update function does use the request object, and uses destructuring to extracts form data as parsed by wrap-params.

Depending if a revision was supplied, a new document is created or an existing one updated. Then, the page is shown.

Note how Moustache now delegates POST requests to update and GET requests to show.

commit 11588b8f1e591ea6415515ffa21e70ed630eef91

I added a Java library for Markdown parsing.

The markup function also replaces WikiLinks with an HTML link.

commit 235c551d57786f79c1867452de37b079a59606bd

Getting ready for deployment.

I removed the debugging wrappers and the var syntax(#’wiki).

Jetty now gets the port number from the environment/Foreman. This means it now runs at port 5000.

Install Foreman with gem install foreman

I added a Procfile according to http://devcenter.heroku.com/articles/clojure