Dominant misconceptions of recessive genes

I still remember my 10th grade Biology teacher explaining that because blonde hair is a recessive trait it will slowly vanish off the face of the earth. Recently I read a news article with a similar claim, and had an argument with a few other biology and genetic majors. So I wrote a simulation.

TraitSim is an animated toy for exploring random, neutral gene proliferation with brown and blue eyes as an example. I also wrote a python version of the simulation and ran it tens of thousands of times. Thanks pypy for the 8.3x speedup! Surprisingly the chance to win the gene-race is linear with the gene’s initial prevalence as can be seen in the following graph thanks to matplotlib.

The thing with dominance is that it affects the gene expression which can be seen in the following graph:

 

And here’s the source that generated these from the data. There’s more information in the project page on github. These github pages are strange creatures which I’m not sure how to work with yet. Can I modify the CSS or structure somehow without losing the benefit of the page generator?

redditp – a fullscreen presentation with reddit

tl;dr – add a “p” before the “.com” to any subreddit you visit and voila, you have a fullscreen presentation of all the images.

I like to show my friends cool stuff on the internet but browsing is a real conversation killer. You can’t really lean back, talk and have fun with friends while operating a website, surely not one as clunky as reddit. Even though RES does help.

So I just had to make this “hands-free” reddit mode. Where I can see:

Easy!

Welp, not that easy, there was a lot of CSS to handle and the design right now is dead ugly but functional. Also, many stories on reddit aren’t images and I skip those that aren’t in a quirky way. If the url’s 4th character from the right is a dot, I display it. That’s a hack that works for imgur (which is most of reddit’s images) so I’m using it for now until I have more time to fix it. Any suggestions are more than welcome - help improve redditp on github! Also, comics are a pain to watch right now. I might implement some sort of scroll wheel zooming in the future, though that really is a bit of a different use case that might deserve a different site.

I guess not too surprisingly the first 200 visits where mostly to gonewild. You internet you….

edit - here are some stats from the launch night

redditp launch night stats

redditp launch night stats

Pendulums, WebGL and three.js

Here’s the waves pendulum three.js simulation I made.

 So I wanted to simulate a magical pendulum with waves to prove my point that the shapes are the result of a dead simple arithmetic progression. I was almost correct.

After testing, I saw that when the frequency is an arithmetic progression we get the awesome patterns. The problem is that achieving such a feat by modifying the length of the strings alone is a bit harder. Here’s omega, or the angular frequency from hyperphysics:

w = sqrt(g/L)

So all I had to do was choose omegas, increment them and from that calculate the string lengths. I got mixed up and solved the problem in a much more complicated way.

Anyhow, by faking it (choosing my omegas with bogus L’s) I get a prettier result. Headache averted. I’m not sure these swing angles are simple pendulums anyway.

WebGL and three.js are indeed awesome. It does have its gotchas but I was just so impressed with http://lights.elliegoulding.com/ and other things in the three.js gallery. It’s amazing how simple and accessible opengl is now that it’s in the browser. The “hello world” of about 20 lines for a rotating cube was good though I think it should include the WebGL detection in it.

Scrolla – A Javascript Scroller

Here it is – Scrolla for Queen’s Bohemian Rhapsody.

This was a fairly straightforward project. Reddit’s graulund made a beautiful comic depicting one of my favorite songs – Queen – Bohemian Rhapsody. Because I believe in lazy people I made this auto-scrolling javascript. The youtube videos doing the scrolling just weren’t awesome enough. jQuery’s “animate” is used to scroll, swfobject to embed a chromeless youtube player that’s pushed out of the frame. Please do “view source”.

I tried to make it easy to reuse “scrolla” so all the important variables are at the top of the html file (which video, which picture and at what rhythm to scroll). The “scrolla” thing could actually be a cute web app where people submit their scrolling pictures with youtube background sounds or music, but I didn’t have the diligence for that just yet. If anyone tries to make another scrolla I’d suggest to use the buggy but useful feature I added – suffixing the url variable “?at=30″ will start the scrolling and youtube video at 30 seconds. When editing a 5 minute long song by Queen, I found this feature absolutely necessary. Without it I would’ve been in replay hell for big piles of minutes.

Javascript’s Global Scope and Google Wave

Dmitry Baranovskiy said something that bit me the other day:

JavaScript’s global scope is a public toilet. You can’t avoid going in there but try to limit your contact with surfaces when you do.

Google wave stops calling your gadget callback functions if you do the following in your javascript:

name = "something, anything really, it doesn't matter"

That’s it, that’s all it takes to break a gadget. This bug was very hard for me to find and fix. I now realize it’s noobish not to place ‘var’ before every local variable and that the most polite thing would be to always use var and fight the scoping with only one uniquely named global. Javascript did a big nono when it decided that by default a variable is global and the special ones are local. Really that’s just one insane design choice.

What’s in a “name” as one might ask is something like
“wgadget_iframe_8″ for which I didn’t really care enough to dig any further. Just know that you can’t touch it when making a gadget for google wave.

Btw the gadget I made’s called “4 in a wave” which allows you to play the classic game face to face (thumbnail to thumbnail) with your opponent. A bot for playing alone is coming soon. To use this gadget in a wave just click the puzzle piece and paste this url:

http://4inawave.googlecode.com/files/4inaawave.0.8.xml

Python Programmers Writing Javascript Beware

Call me silly for not reading the docs, but this bug was very hard to find. Dictionaries in python are NOT the same thing in javascript. The curly braces mean it’s an "object literal" and the keys don’t need the quotation marks. For example:

var x = { NAME: 123, Something: "ok"}

Is the same as the following code:

var x = {}
x['NAME'] = 123
x['Something'] = "ok"

Which means that if you had a variable named "NAME" and you expected it’s contents to be the key, then you’re going to have a royally hard to find bug (especially when developing for an already obfuscated framework such as Google Wave).

This is even worse because JSON causes you to believe the quotation marks are needed. If there’s a place to file a JS enhancement proposal, I would, but I doubt this inconsistency would annoy anyone but a pythonista.