My Octopress Blog

A blogging framework for hackers.

Computers Totally Work This Way

Mom, Dad, relatives. All who will ask any computer-scientist friends for help with their computers, or who put any stock in prime-time shows.

This is not how computers work. Just… just… no.

But seriously, if you need me to “vector in on that guy,” or “find the right eigenvalue” or perhaps “apply the right algorithms,” think again.

Found at Unplggd.

From my friend Tyler, Red Dwarf has something to say on the subject:

日本!

I arrived in Japan yesterday for SIGGRAPH Asia 2009. It’s been a long time since I’ve been here, and it’s nice to be back.

It turned out that a few KAUSTicans were on the same flight as me, and we had a good time talking shop while waiting for flights. Good guys - I look forward to hanging out with them at the conference.

It wasn’t until I stepped off the plane and saw that my travel companions didn’t look to be immediately at ease in this country that I realized that Japan is almost a second home. Outside of the US, it’s the country in which I’ve spent the most time, though Japanese is not my strongest second language. Still, I was able to pick up right where I left off in terms of daily life without missing a beat - it’s a different city, but the people and places are recognizable.

Glad to be back, Japan.

A Little Challenge (Part 1 of 2)

Several months ago, I was given credentials to download a piece of software, and I needed to download another copy only to find that I had forgotten the password. I anticipated it would take quite a while to email the people in charge, and on a whim I decided to take action. Right click, view source.

To my surprise, all the authentication was done in JavaScript, though in all fairness it was “encrypted.” I’ve changed the underlying keyphrase in a code example, and I pose a small puzzle - find the password.

You may find jconsole helpful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var pass=new Array()
var t3=""
var lim=8
pass[0]="fE13Cw9emtKIg1F"
pass[1]="wKTuZEy387Im8b2"
pass[2]="3NKevEgjpWWwmSE"
pass[3]="CryO6BmP9XpUlke"
pass[4]="8R4Gf2sgs5Xs5KI3"
pass[5]="62GZJ9Dzc2y8lBTU"

var extension=".html"
var enablelocking=0
var numletter="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var temp3=''
var cur=0

function max(which){
return (pass[Math.ceil(which)+(3&15)].substring(0,1))
}

function testit(input){
temp=numletter.indexOf(input)
var temp2=temp^parseInt(pass[phase1-1+(1|3)].substring(0,2))
temp2=numletter.substring(temp2,temp2+1)
return (temp2)
}


function submitentry(){
t3=''
verification=document.password1.password2.value
phase1=Math.ceil(Math.random())-6+(2<<2)
var indicate=true
for (i=(1&2);i<window.max(Math.LOG10E);i++)
t3+=testit(verification.charAt(i))
for (i=(1&2);i<lim;i++){
if (t3.charAt(i)!=pass[phase1+Math.round(Math.sin(Math.PI/2)-1)].charAt(i))
indicate=false
}
if (verification.length!=window.max(Math.LOG10E))
indicate=false
if (indicate)
alert("Correct password.")
else
alert("Invalid password. Please try again")
}

You can also get it in a testable html page.

SIGGRAPH Asia 2009

My numerical linear algebra professor is sponsoring me to join him at SIGGRAPH Asia this year in Yokohama, which conveniently affords me the opportunity to return to Japan.

I went to SIGGRAPH for the first time this year, and am really excited to get a chance to go to another, especially in Japan. Thanks to Mrs. Redman, who arranged my flight. I’ll arrive about a day early, and then I’ve got about a week to myself after it. I’m planning to take full advantage of the snow, going to Nagano for five of those days - just booked the hotel.

I left Japan a few years ago not eager to return, but I’ve been feeling very nostalgic for it lately. And hey, it will be my second Christmas there!

Programming Praxis

I’m all for sharpening the saw, and working on little puzzles. In that vein, I recently came across a site called Programming Praxis that suggests tasks from implementing heapsort to writing AI to play the game Mastermind.

I don’t work on their puzzles as often as I like, but if you’ve got a little bit of free time, they’re worth checking out.

OpenGLot3D Video

I gave ScreenFlow a shot, and it was definitely the best screencasting tool I found. Thanks to it, I can now share a more dynamic sense of the capabilities of this plotting library.

OpenGLot3D from Dan Lecocq on Vimeo.

OpenGLot Release

A short while ago I posted a new release of OpenGLot, which featured parametric curves, scalar fields, contour lines and flow fields all implemented in GLSL shaders.

And they support time dependence.

It can plot virtually any function in x, y and t, and on my MacBook with its NVIDIA GeForce 9400M it has been getting 10k+ fps. I’m still a little surprised by this number, but it seems to be running at that speed.

[caption id=”attachment_747” align=”aligncenter” width=”300” caption=”Flow (vector) fields appear as advected dye. They’re currently streamlines, but in the near future I hope to support streaklines and particle flow as well.”]Flow (vector) fields appear as advected dye. They're currently streamlines, but in the near future I hope to support streaklines and particle flow as well.[/caption]

[caption id=”attachment_748” align=”aligncenter” width=”300” caption=”Scalar fields appear as a mapping of height onto color. If this function were to be plotted in 3D, it would like a sheet rippling, but sometimes it’s more useful to see it in 2D.”]Scalar fields appear as a mapping of height onto color.  If this function were to be plotted in 3D, it would like a sheet rippling, but sometimes it's more useful to see it in 2D.[/caption]

On of the great thing about implementing this on the graphics card is that it doesn’t require much CPU time on the machine running it. Even at 10k frames per second, my MacBook never uses more than 30% of a single core’s time. A place where this particularly shines is on tiled displays - a bunch of HDTVs tiled together to run as if it were one large screen. In such setups, a computer will control 2-4 screens, and each computer’s graphics card has enough power to run the animation for its portion of the screen. There are still some bugs to be worked out, but I ran a proof-of-concept on one of the tiled displays at KAUST.

[caption id=”attachment_752” align=”aligncenter” width=”300” caption=”Running a demo of OpenGLot on a KAUST tiled display”]Running a demo of OpenGLot on a KAUST tiled display[/caption]

Lately I’ve been working on getting the 3D analogs of the various 2D primitives working, again all with time dependence (it’s the support for animation that really makes this shine in my mind). So far it’s surfaces, parametric curves and surfaces and flow fields, but the flow fields have some work yet. It turns out that while modern hardware is definitely capable of handling 3D flow fields, it doesn’t actually make much sense when you see the result - it’s just too busy. To be able to easily visualize flow in 3D is very much an open problem.

[caption id=”attachment_753” align=”aligncenter” width=”292” caption=”3D streamlines end up just becoming confusing more than they are helpful.”]3D streamlines end up just becoming confusing more than they are helpful.[/caption]

In order to get some interesting shapes working, I had to add support for cylindrical and spherical coordinates which is actually providing an interesting challenge - how best to generate the shaders. The shader source code (that runs on the graphics card) is generated and compiled when you run OpenGLot, and I’ve not found an altogether easy and intuitive interface for adding simple coordinate transformations to it. Still, it works, but the programatic interface will likely change.

[caption id=”attachment750” align=”aligncenter” width=”292” caption=”This is a torus of sorts, which I got as an example from Grapher.app”]This is a torus of sorts, which I got as an example from Grapher.app[/caption] [caption id=”attachment751” align=”aligncenter” width=”292” caption=”This is the same torus, just colored by using its surface normals as RGB values”]This is the same torus, just colored by using its surface normals as RGB values[/caption]

In order to determine surface normals (which are something usually determined when one defines the geometry of an object), the vertex shader approximates various derivatives numerically. So far, the shading results have been pretty decent.

[caption id=”attachment749” align=”aligncenter” width=”292” caption=”A trigonometric function, colored by mapping the surface normals to colors”]A trigonometric function, colored by mapping the surface normals to colors[/caption] [caption id=”attachment755” align=”aligncenter” width=”292” caption=”The superimposition of two trigonometric functions, lit based on their surface normals and a texture to give visual clues about distortion”]The superimposition of two trigonometric functions, lit based on their surface normals and a texture to give visual clues about distortion[/caption]

I’m still working on making video of this in action available, but so far a number of the tools I would usually use have come up short. I’ve been trying to integrate a video encoder into a utility library for OpenGLot so it can record video straight out of the box, but the framerate is still too low.

Flood

Yesterday morning, I woke at 6:15 to the all-to-common fire alarm. Prepared to sleep through it if necessary, I went to my window to check for smoke or anything that might indicate that this wasn’t one of the dozens of false alarms. What I found was rain.

DSC_0052.NEF

Rain like cords was falling in Saudi Arabia. The streets were wet, and excited, I ran to get my camera and started taking pictures. I threw some clothes on, and ran around campus to try to document what I believe to be a very rare event here. I called several of my friends to make sure they were awake and witnessing this.

The rain let up about 7:30, and soaked and I tired I headed back to my building to get some sleep when I encountered several other students who also wanted to just feel the rain on their faces. We walked around campus to see it wet, but ended up surveying the damage. Students had ceilings collapse, water running out of light fixtures, flooding in their apartments - the list goes on.

DSC_0264.NEF

A sunken area of campus had turned into a lake (based on what it’s like when it’s dry, it must be 4 meters deep in some places), and some roads had become impassable rivers. Encountering a couple of students on motorcycles unsure if they should try to cross, I was reminded of Oregon trail. In the end, they forded the river.

DSC_0328.NEF

Tyler and I moved on, the water now thigh-high in the middle of the road. Cars’ mufflers were bubbling through the water, and one had to worry about the wake of passing cars. The womens’ residence was evacuated, and many families packed their kids in the car and left in search of higher ground. The timing was sweet and sour - it was the last day before break and school got cancelled on account of rain, but most students were leaving the country for the week, and some will return to find unlivable and extensively damaged homes.

DSC_0352.NEF

Rains like these are extremely rare in the area, and so I understand the lack of preparation. I don’t understand the shoddy craftsmanship of the homes, but that’s a running issue. Tonight’s Thanksgiving dinner will be a reflective one for certain. One exasperated student, waking to water pouring on him, household wiring fried and water running down the stairs like a waterfall felt that this was the last straw. He seemed to be set on the decision to return home at the earliest possible time.

It seems he’s not alone, and the school is expecting a non-negligible portion of the students to not return after winter break, though some are talking about not returning from Eid break at the end of next week. I hope for all our sakes and for the sake of the school, that the administration can refocus, get their act together and get their sometimes incredible mismanagement under control. We all came because we wanted to see KAUST succeed, and we hope it still can.

DSC_0387.JPG

That said, I would like to offer praise and criticism; the response from emergency services was what I’d expect in a modern country. Water tankers were on the streets, pumping out massive amounts of water, within four hours of the rain. The fire department helped evacuate a number of families, and each student was actually contacted by phone to make sure he had a livable apartment for the time being - those who did not were moved to safe lodgings. My criticism is this - why are not all of our other, very real concerns and problems not pursued with the same tenacity and efficiency. Why did it take a small disaster for KAUST to shine?

I took some more photos as well.

Zsh (or Bash++)

A professor of mine mentioned that he didn’t use bash but Z shell (zsh). I asked him about his choice and he said that it happened years ago when he asked a system administrator how to accomplish a task in bash and the guy replied that it was really easy in zsh. There have been worse reasons to switch, I suppose.

(Incidentally, the best way I’ve found to improve your command-line-fu is to work near system administrators. They have the most amazing bits of command line ninja magic you’ll ever see.)

I decided to give it a shot this evening and after 30 minutes of use, I’m switching. The features I’ve liked thus far as that when you want to search for a command you recently ran, you don’t need any of the ctrl-r nonsense. One simply begins the command as he remembers it and presses up. Old functionality mapped to the intuitive keystroke. You can scroll through your command history by pressing the up arrow key in bash, but to search, it’s a different story.

The feature that clinched it for me is that it has better autocompletion. If you are not using tabs to autocomplete, you are wasting keystrokes and make typos, but something I find frustrating is that when I want to ssh into some computer with some long and difficult-to-type name, I had to search my history for it. Or, in zsh, you can tab complete the name. It remembers that stuff! Imagine that!

Of course, there’s a very real possibility I’ll switch back if I run into too many gotchas, but this many niceties this soon in make mean think that the good will outweigh the bad.

The Art of Failure

I’ve failed before, at many things, and it is a habit I can’t seem to break. It’s inevitable that things won’t work (especially not the first time) and in fact programmers know that it’s a beautiful thing when code compiles the first time, let alone works correctly the first time.

With graphics, the results are sometimes cool, sometimes horrifying and sometimes beautiful. I make a habit of documenting the results of broken code as much as I can, and after a recent one, I thought I’d share some of the more interesting ones.

[gallery link=”file”]