Duane’s Quick Posts

 

This is what a republican death spiral looks like

Powell: "Let's be more inclusive."
Limbaugh: "Powell should get out."
Cheney: "I'd pick Limbaugh over Powell."

... so they all rolled over and one fell out ...

Article at the NY Times.

Loading mentions Retweet

Comments [0]

Visualizing Typed Functions

As I've worked in Haskell over the past several months, I've noticed that my mind has kind of implicitly modeled functional programming as a visual/mechanical representation of concepts.  I'd like to make the ideas more explicit, however, so I'm writing this post and cooking up some graphics.  I wonder if others have similar "internal representations" of functions, and if perhaps others might suggest improvements over my model.


The basic idea is that a function is a semi-circle with inputs on one side (left) and the output at the right.  Colors represent types.  Here is a function that takes one input and produces one output (of the same type):


Haskell would type this as "a -> a".  Next, we have a function that takes one type and returns a different type... e.g. a hashing function might take a string and return an integer:


(Please ignore the vertical stripe, it's an artifact of my poor Inkscape skills).  We can also create functions with more than one input, of course, so here is a binary function.  It might be the '+' operator, or some other binary operator, e.g. "a -> a -> a":


Haskell and many other languages also have the concept of higher-order functions, i.e. functions that take functions as inputs.  Here is a function that takes a binary function as input, along with another input, to produce an output of the same type:


There exist polymorphic types in many languages as well.  In Haskell, for example, the list is a polymorphic type--it is a linked list of any type you want.  I imagine these polymorphic types as "banded colors" so that the bands contain another type (color).  Here is what the "head" function might look like ("head" returns the first element in a list):


Finally, here is a composite of all of the above visualizations.  The "map" function in Haskell is a function that takes a function and a list, and applies that function to each element in the list, returning a new list with the "mapped" elements:




The type signature for the "map" function in Haskell is "(a -> b) -> [a] -> [b]".

With these functions visualized, one could make a kind of "drag and drop" interface for Haskell programming, although that isn't really my intention.  I admit this is a little convoluted even for the purpose of visualization, but at least it's a starting place.  Does anyone know of another system or better representation?

Loading mentions Retweet

Comments [0]

Silkworm Game written in Haskell

The semester is over, my final project was a success (at least in that I passed the class) and it's time now to release the game I made for Graphics 455: Silkworm!


This is my first full application in Haskell.  The process has been an enlarging experience--I've come to really enjoy the mental work that goes into thinking about a program in a functional way.  I highly recommend the challenge to other software engineers.

Silkworm combines the Hipmunk binding to Chipmunk 2D Game Dynamics with OpenGL, and GLFW (an alternative to GLUT).

It's built to work on Mac OS X, but it uses cross-platform libraries so it should be fairly easy to port to other platforms.  The source code is here and below are some screenshots:







                           
Click here to download:
Silkworm_Game_written_in_Haske.zip (720 KB)

Loading mentions Retweet

Comments [0]

Tools from this Semester

Class is now done.  My last final exam was yesterday. More than any previous semester, I used a wide variety of computing tools to finish my work in class.  Here are a few of the ones I put to use:


1. Weka, an open source machine-learning workbench (I used it in bioinformatics but it is a general-purpose tool that could be applied to any field).
2. UCSC Genome BrowserNCBIRCSB Protein Data Bank, for making sense of genetic data.
3. Matlab, a non-free tool for writing math-intensive software (I used it to run Charles Kemp's "Discovery of Structural Form" code... very neat work.)
4. OpenMPOpen MPI and CUDA for writing parallel code in C.
5. OpenGL for writing a 3D game for graphics class.
6. Wings3D for creating 3D meshes for my game.
7. The open-source R Project for statistical analysis of data.  I also used it for my Stats 221 class.

Posted for future reference :)

Loading mentions Retweet

Comments [0]

Investigate the Torturers

I really don't like blogging about this kind of thing, but the battle between my stomach and my conscience often leads to a win for the conscience.  The United States should be a world leader in moral capacity and ethical treatment of even the vilest of characters.  Somehow, we failed at that role between 2002 and 2007.  FireDogLake reports:


According to the May 30, 2005 Bradbury memo, Khalid Sheikh Mohammed was waterboarded 183 times in March 2003 and Abu Zubaydah was waterboarded 83 times in August 2002. 

The author concludes:

The CIA wants you to believe waterboarding is effective. Yet somehow, it took them 183 applications of the waterboard in a one month period to get what they claimed was cooperation out of KSM. 

That doesn't sound very effective to me. 

signed the petition to investigate and prosecute.  Although they wouldn't guarantee it to their victims, at least the torturers deserve justice.

Loading mentions Retweet

Comments [0]

The Gift Economy

I liked this article by John Sviokla about why people are willing to work for nothing: it's a different economy altogether.  Once a person has left the ground-level of income-for-survival and is flying in the upper stratosphere of meaning, purpose and contribution it makes little sense to desecrate that higher ideal with a token payment in dollars.


I think most people, like me, straddle both economies: we do some things out of a pure intent to help, and other things to pay the bills.  The in-between is somewhat murky and can either feel like we have to compromise our ideals due to the reality of life, or else change our ideals.

There's more to think about here, but I have finals this week so I have to go.  Perhaps I'll write again on the subject soon.

Loading mentions Retweet

Comments [0]

Github Gets Issue Tracking and Voting!

Wow.  Just in case Github wasn't already the coolest social site for coders, it now has "issues"---a bug tracking area for each software project.  And it gives everyone the ability to vote for the issues they most want fixed!


This is really awesome.  Git and Github have already revolutionized how software can be created by distributed teams---and now I think we'll see a further democratization of software development with this feature.  Way to go mojombo and team!  :)

Loading mentions Retweet

Comments [0]

Human Intelligence

This New York Times article talks about the malleability of intelligence and the recent evidence that shows IQ is not quite as genetic as was once thought.  Anyway, this little snippet kind of blew me away:


Another indication of malleability is that I.Q. has risen sharply over time. Indeed, the average I.Q. of a person in 1917 would amount to only 73 on today’s I.Q. test. Half the population of 1917 would be considered mentally retarded by today’s measurements, Professor Nisbett says.

I've always suspected that there is a gentle progression toward a more educated, intelligent society.  But I thought it was only visible on the order of thousands of years.  If true, this claim by Prof. Nisbett will require me to update my views.  I suppose if you consider education as the factor that has improved our IQs on average (rather than genetics), that claim makes sense.  We are better organized today, in spite of the disaster that is No Child Left Behind.  In any case, I hope we can continue this upward trend in education so that children 100 years from now can look back on my youth and remark that I must have been mentally retarded :)

Loading mentions Retweet

Comments [0]

How to Create an Icon for a CD on Mac OS X using Linux

This adventure took longer than I expected, so I am posting what I've found here for others.  The goal is to create a CD with a custom icon for Mac OS X, with one caveat---it needs to be created on a Linux system.  The software to use on Linux is called "cdrtools" and includes a command-line tool, "mkisofs".  You can also install cdrtools on the Mac (using the MacPorts system) for testing purposes with "sudo port install cdrtools".  Here's the recipe:


1. Find or create a ".icns" file that includes the icon you would like the CD to have when you pop it in the drive.  I found a hint here that helps you to convert a regular Mac OS X icon to a .icns file. [Note: this step was done on a Mac]

2. Copy or move the file to a directory with the contents of the CD.  Rename it as ".VolumeIcon.icns". The preceding dot is important, and the name must be exact.  I used the shell / Terminal to do this since the Finder isn't always friendly to seeing and creating hidden files.

3. Create an empty "Icon\r" file in the directory.  In the terminal, I can do this with "touch Icon^V^M" where "^V" means "control V" and "^M" means "control M".  Just the existence of the file is enough--it tips the operating system off to know that it should use the .VolumeIcon.icns file.  [Note: it appears to be possible to also use the "SetFile -a C mycd/" command when on a Mac to change a bit on the directory itself.  This bit also notifies the operating system that it should use the .VolumeIcon.icns file---however, SetFile is not available on Linux.]

4. Use mkisofs to generate the iso file: 

mkisofs -hfs -r -V 'My CD' -o mycd.iso mycd/

This assumes the contents of the CD (as well as our two files above) are in the mycd/ directory.  Once the mycd.iso file has been generated, it can be burned directly to a CD.

Loading mentions Retweet

Comments [0]

Is the "power grid spies" story part of a PR campaign?

When I first heard about the attempted spying on our US infrastructure and subsequent early discovery of the infiltration, I thought "Oh, whew, good thing we caught them."  But on second thought, Robert Graham has a good point: is this another one of those Bush-era "few facts and government officials said" stories?  Could it be part of a PR campaign to convince us that we need to give the president power to "switch off the internet" so to speak?


Read the opinion piece here.

Loading mentions Retweet

Comments [0]