Tech Addiction

Several days ago, Gizmodo posted a quiz about technology addiction. Somewhat nervously / reluctantly looked through the questions, and was pleased to find that I fit into their “Coffee Fiend” category. Well, rather, I was pleased that I didn’t fall in any of their worse categories, despite working with computers for a living. There are even some places I could do with shaving down that would get me into their “Social Drinker” category; I see this as proof that one still can be in a tech field and not be a total tech fiend.

Some of their more amusing / revealing / interesting questions were:

2. Do you sometimes bring your laptop when you sit on the toilet?

Just for the record, I do not. But, I know people who do, and let’s face it – that’s why the iPhone was invented in the first place.

8. Have you ever changed vacation plans based on wi-fi availability?

Well, technically yes, I have done that. But it was deciding between two capsule hotels, and I was going to be there for a week for a tech conference. I think that’s justified.

10. If your house were on fire, would you run in to rescue your laptop?

I have sort of done this already. Fire alarms are a regular feature of KAUST, and one day we saw smoke coming from the building we were in as one went off. Ben and I looked at each other for 2 or 3 seconds, then both immediately grabbed our laptops and dashed out. In all fairness, most of my work is on there (I’m doing more off-site backups for the important stuff), and it’s the only computer I have in this country. What is life without computer?

35. Do you tweet or read blogs while watching movies at home?

Well, I do play Tetris. That’s my tech meditation time.

Tagged with:
 

It is extremely easy for computer scientists (well, and the rest of humanity) to get entrenched in their ways. You’ve learned and taken the time to become a master of a programming language, or tool, and it’s a serious time investment. As such, new tools generally have to be very compelling in order to get someone to switch. For example, I’m a recent svn-to-git convert, and am often met with horrified looks when I suggest others give it a shot. A visiting professor I spoke to yesterday said that it would be years before they stopped using svn.

Recently, I’ve begun using sshfs. It mounts a volume over ssh and appears as any normal folder on your computer. It behaves that way at the command line, or your text editor, or as far as VLC is concerned. For development, I had always maintained a local copy and rsync’d changes to the remote machine I was using. It worked well enough, and was often more convenient than using a tool like Cyberduck.

Aron recommended sshfs, and though it took me a while to try it out, I’m hooked. No more trying to remember if I’ve synchronized my code with the other machine I’m using, only editing and saving. It’s really easy when you have ssh keys set up as well. To mount your home directory on a remote machine:

$> mkdir datastore_mount
$> sshfs datastore: datastore_mount

And now, I’ve got access to remote files on datastore as if they lived in the directory datastore_mount. Unmounting is business as usual:

$> umount datastore_mount

Try it, use it, live it. You won’t regret it.

Tagged with:
 

Snorkeling

For the past semester, many of my friends here have been enjoying the Red Sea, diving regularly. One even went on a two-week research cruise, making three to four dives a day.

‘What,’ I wondered, ‘could possibly be the fascination?’

Growing up in Colorado, playing around on the beach meant going to Boulder Reservoir, which isn’t much more than an enormous swimming pool. Just not much remarkable about it. The only real beaches I had been to until now were in San Francisco and Japan, and the novelty wore off pretty quickly.

This last weekend, I decided that I ought to give it a try, and not being certified for diving I went snorkeling with my friends. We drove to a private beach (which was a treat in itself – men and women can mix, and music plays over the loudspeakers. These are things I’ve learned to not take for granted), rented gear and got in the water. On the dock, I was excited when I saw a small coral growing in the shallows. It couldn’t have been more than 10 centimeters in diameter but thinking about exploring the beach for more such treasures was enticing.

We waded out and put on our flippers, and then our masks. I dipped my head down, ready to explore, and instantly my head popped right back out of the water. “Guys! Guys!” I shouted to my friends. “There’s a freakin’ million fish here!” They chuckled knowingly, and I realized this is what they came for.

I just could not get in the water fast enough. There were so many fish I had never seen except for in aquariums, brightly colored, quick, and just stunning. Thousands of them from deep blues to iridescent purples, all swarming around beautifully-colored coral and anemones. All told, I spent about four hours tooling around the reef, examining fish at the cleaning station, clownfish in their anemones and predators lurking near the surface.

On leaving I instantly felt like a tree-hugging hippie, and felt a need to protect the ocean. Ok, sure, it was a bit short-lived and I feel like someone who’s hopped on a bandwagon, but it’s an incredible world down there. You see shadows off in the “distance” (though it’s usually only 30 feet away) shimmering and swimming around. Floating in the sea, weightless, above the sheer cliff faces of 20, 30 or 40 feet is a unique sensation. I tried to compare it to hiking and climbing mountains, but it occurred to me that unless I learn to base jump, I will never see that kind of geographical structure from the same relative perspective – hovering above it.

Between dives (well, my friends were diving while I was snorkeling) we’d pull out a book of Red Sea fish and try to find all the ones we’d seen. The camaraderie of stories of dives past and fish seen was nearly as satisfying as the experience of being in the water like that.

I’m exploring getting certified (either through PADI or BSAC – we have both available here) so that I can join my friends on deeper adventures, but in the mean time I’m going snorkeling as often as I can. Forgive the pun, but I think I’m hooked.

Tagged with:
 

Monkey Business

Nagano (well, Yudanaka) is famous for it’s “Monkey Park,” an open space where Japanese Macaques relax in large groups in the natural hot springs. Visitors can walk among them as they graze, groom, and occasionally, fight.

DSC_0023.NEF

The younger monkeys are pretty playful, climbing ropes and poles, and rough-housing with one another. The adult monkeys seem more interested in eating the food provided to them, a mix of barley and other grains. There seemed to be some areas used mostly by families (these were inaccessible to human visitors) and others that seemed to be dominated by younger bachelors. Fights would break out from time to time, but nothing too serious.

DSC_0052.NEF

Japan is known for their natural hot springs, and the monkeys take full advantage. The day I was there, it was about 3 degrees Celsius, and the water was pretty tempting.

You can get pretty close to these brazen animals, but do not touch. Occasionally they will grab onto you, but I only saw one instance of this; a group of us were watching a couple monkeys playing and banging against a sign, when an attention-starved lad came up and tugged on one man’s coat to get his attention. Still, they’re pretty aloof to our presence for the most part, and will walk and eat within a few feet of you.

DSC_0106.NEF

I kept thinking of them as terrestrial Ewoks, or furry seven-year-old human children, but the opposable toes are kind of unnerving. They often appear so human that it’s hard to remember that they’re still very wild.

DSC_0239.NEF

They cry and scream at one another, but these noises serve as low-priority warnings more than anything else.

If you even get a chance to visit, take full advantage. Best US$5 I spent in Japan. More photos on flickr.

Tagged with:
 

I’m working with WebGL and as such, I’m discovering some quirks about OpenGL ES 2.0. I have been using display lists as long as I’ve been using OpenGL, but WebGL doesn’t have support for them. So, I’m buckled down and familiarized myself with vertex buffer objects, the (perhaps better) alternative.

At any rate, I need to render a regular 2D grid, and as it doesn’t support quads, either, I was forced to use triangles. In the interest of getting things running, I just provided a wasteful list of discrete triangles. This is wasteful because it references many more vertices than necessary – I ended up declaring 6n^2 vertices when in reality there are only n^2 + n + 1 unique vertices. This worked fine, until I wanted to increase the resolution. It turns out, JavaScript doesn’t like large arrays.

That’s fair, because the implementation was pretty wasteful. A triangle strip was the best choice anyway. A triangle strip is a highly compact form of representing a mesh. For n triangles, it requires only n + 2 vertices defined. Well, that’s roughly true. We’ll see another case in a minute. It’s useful when many triangles share vertices, and perhaps I’ll let Wikipedia’s explanation stand.

It wasn’t immediately obvious how to define a grid out of a single triangle strip and so I got out a pen and paper. I kept in mind a neat trick: if in a triangle strip, you need to skip the use of a vertex, a vertex can be introduced twice in a row. That is, if I need triangles (6, 3, 7) and (7, 11, 6) in that order, you can just make your strip with 6, 3, 7, 7, 11, 6. You can think of it as if there are two triangles created (3, 7, 7) and (7, 7, 11), but they have no area and a degenerate case – a line. Furthermore, these lines lie on triangles already defined.

Perhaps the obvious choice doesn’t yield any results, and in fact in this layout, it can’t be easily done (you have to have vertices appear three times in a row):

This is a bad idea for a topology if you want to use a single triangle strip.

To better convince yourself, try to come up with a good way to put this in a triangle strip. I’ll make the case that it is pretty difficult with a claim from graph theory. In order for a triangle mesh to be turned into a triangle strip, each consecutive triangle must share an edge. We can then think of the mesh as a connectivity graph (the dual of the mesh) and then the problem will emerge more clearly:

The dual graph of the bad idea.

To make the triangle strip “nice,” we ought to be able to visit each node once and exactly once. There’s good and bad news in this – it’s the same problem as finding a Hamlitonian path which is NP complete. The good news is that if we find a solution to our small problem, we’ve found a solution to all such grids (with arbitrarily many triangles). Note that we don’t need an Eulerian path.

If you stare long enough at the above connectivity graph, you’ll hopefully convince yourself that there’s no way to traverse it visiting each node once and exactly once. Go ahead and try – it’s pretty infuriating.

Looking at how we would traverse one strip (triangles a, b, c, d, e and f) actually gives us a clue. A triangular strip for that case would be 0, 4, 1, 5, 2, 6, 3, 7, and happiness ensues and we should move onto the next row. Unfortunately, in the context of this new row, we’re starting in a different place (topologically) than we started with the first strip. Vertex 0 has two connected neighbors in its row – 1 and 4. Vertex 7 has three in its row: 6, 10 and 11. It turns out we can change up the topology to remedy this simply:

A much better topology for drawing this with a single triangle strip.

A much better topology for drawing this with a single triangle strip.

We can also see that this is a much better solution by looking at this new graph’s dual:

The dual of the better topological choice.

You can probably easily find a Hamlitonian path in this case. But this still leaves us with how to determine the vertex orderings. We decided that the first row ought to be 0, 4, 1, 5, 2, 6, 3, 7, but moving on from there we need a bit of “glue” to move onto the next row. We insert 7 again, and then continue on from there: 7, 11, 6, 10, 5, 9, 4, 8. A bit more glue for the third row: 8, 12, 9, 13, 10, 14, 11, and 15:

An alternative representation of the vertex ordering

Looking at the indices from the first row, starting at 0, we can get the next index by alternately adding 4 and then subtracting 3. On the next row, we’ll continue to add 4, but then alternately subtract 5. The 4 is derived as being the number of vertices on a side (if there are n divisions, then there are n+1 vertices), and the 3 and 5 are explained by the fact that we need to change columns in the mesh, by one step at a time.

An clean implementation is not trivial, but not extremely difficult. In terms of results, I can fit more than 4 times as many vertices into the mesh than with a per-triangle implementation. And to boot, it has cut the work of the vertex shader a great deal.

Tagged with:
 

webGLot – A Preview

I’ve mentioned WebGL before, and I think it could be very important. There is a competitor from Google, but like OpenGL and OpenCL, this API is managed by the Khronos Group and that fact appeals to me. Perhaps it’s that I’ve used it fairly extensively, but I really like OpenGL. Despite its quirks, it’s quite powerful.

The big “get” is that it gives programmers access to hardware-accelerated graphics from directly within the browser. There’s a lot of interest in this arena for game development as it would obviate much of the need for separate distributions based on operating system. (Skip to the end for more of an opinion on this subject.)

As such, I’ve been working with WebGL as opposed to the Google-proposed O3D. (I have every intention to explore O3D, time permitting, as there are some jagged edges to the current specification.) The result of this recent toil is a budding WebGL implementation of my OpenGLot project. It’s still in early stages, but in the coming weeks, it should develop even further. To whet appetites, I have a few pictures.

A scalar field, my persistent test function.

A scalar field, my persistent test function.

A 3D surface, again one of my usual test functions.

A 3D surface, again one of my usual test functions.

I seriously doubt that WebGL will every match the performance of OpenGL. Even though JavaScript interpreters are getting faster at a somewhat alarming rate, they won’t match the speed of C or C++. That said, if one can appropriately offload work onto the GPU, it won’t matter as much, but there will always be that overhead.

It won’t so much be a matter of having the same performance, but enough performance. If a person can go to a single webpage and get 60 frames per second performance in a game or tool without having to install software, that’s tremendous. Currently I’ve been getting between 60 and 90 frames per second with WebGLot, and I’m sure I can keep that number up as more features are added.

My hope is that this will be a tool and library that has a wide-enough feature set by the time WebGL is widely adopted that becomes often-used. But that’s just ego. The purer motivation is that if you’re a math teacher, and you want to have interactive demonstrations of Newton’s method, or parametric surfaces, or even flow fields, you can write an application in 20 minutes that does all the heavy lifting of graphing it for you. As long as you can describe the mathematical primitives, you should be able to render it. Of course there will be a general-purpose grapher available for any calculus student who’s having trouble visualizing this or that, too. Or a resourceful PDE student who need to solve his homework (the GPU-based PDE solver will take a little bit more time, but it’s very nearly complete).

In short, the strength of WebGL is that is has respectable performance, and in a year’s time, half the browsers (well maybe not half) on computers will support it, giving the average internet-user access to a wealth of media.

Tagged with:
 

Silly Mistakes

Every programmer has had this, or at least I like to think that every programmer has experienced this – you compile, press “go,” and epic failure. And the joy doesn’t stop there – then the debugging begins. Occasionally, one encounters a bug that gets the better of them, sometimes for hours, sometimes for days, and sometimes for months.

Hairs is pulled, teeth are gnashed, and eyeballs strain, scouring line after line. You try to convince yourself that your algorithm is correct, and that each line of code is justified. And yet, it still gets the better of you.

After perhaps eight hours, you swallow your pride, and ask a trusted friend to take a look. Often the very act of explaining things to another human being is helpful, but sometimes you both have to dig into the code. Maybe a third friend happens upon the two of you, and joins in.

Then, a light bulb goes off. If you’re lucky, it’s a massive structural change that’s required, but sometimes, it’s a single line, or a single word or character, and you suddenly find yourself embarrassed. But do not be. Every programmer I’ve ever met, no matter how qualified has run into these problems. Still, I find it easy to doubt my competence afterwards.

There are rare and beautiful moments when not only does code compile on the first try, but it runs as expected. Few and far between, cherish these when they come.

This is all inspired from a recent bug I tracked down. An embarrassing one. Sure, had I read the 350 or so pages of the OpenGL ES 2.0 specification, I may have caught it earlier, but this was one of those times when it was a single word that had to change. I tell myself that I won’t keep making these kinds of mistakes, and with each conquered bug I gain a tool, an experience point, and that’s what makes one’s craft.

I’ve looked at the time I spend debugging, and I’ve noticed that the time it takes to solve a bug can often be reduced by leaving the problem for a bit. Taking a walk, getting a cup of coffee, or sometimes watching an episode of Arrested Development. The desire to find and fix a bug is a siren’s song – nearly impossible to walk away from, but often a bad idea.

Tagged with:
 

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:

Tagged with:
 

日本!

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.

 

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.

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.

Tagged with: