Archive for the 'coding/software' Category

Das Blinken Bonken!

Seems like end of the year is DYI electronics projects time for me as the Sound Alarm happened round this time last year too.  Well, I’ve been having a ball making Arduino stuff, this time as Christmas presents.  This time I got my documentation act together even more and made a construction tutorial on instructables too!   The code for Das Blinken Bonken is on github, and here’s a video of Jesse showing off the game:

Arduino Sound Alarm

I’ve just completed my second Arduino project, a sound level detector which sets off an “alarm” when there’s the sound level is to high for too long.  I built it for use in a school that wants to provide visual feedback to students when they are being too loud.  The “alarm” is a string of flashing LEDs that’s controlled by an IR-remote, which I reverse engineered using the the arduino itself and the excellent IRremote library to figure out which codes activate the LED string. The IRremote library includes an example that dumps the codes and code types that remotes typically use.  So I just ran that example with my arduino hooked up to an IR detector from adafruit.  It was really quite easy to do.

It’s been a fun project because it’s quite flexible and configurable.  Here’s a short video of the finished product:

For anyone who wants to build one of these here’s a bread-board diagram that I made using the very cool Fritzing package:

The Adruino sketch that powers this is available on github.

Here are some details on the circuitry.  The sound detector is based on the ZX-Sound board. Here’s a nice post on the site that I used as my starting place for building the sound part of this board.  The video helpfully includes a parts list which I sourced from Allied electronics, all except for the mic.  The LCD is the $10 16×2 from Adafruit (their tutorial on wiring it up was great), and I also used their electret microphone.  One note about the microphone is that it’s polarity matters.  If you get it in backwards, it’s much less sensitive.  I found this out purely by accident!  I also used their IR LED.

Here are some photos of assembling the project.

First the prototyping phase:

Then building the connector for the LCD:

Then drilling holes and installing the configuration controls (push-button and pot)

Then assembling and soldering the board with the sound circuit and the trim pot for the LCD as well as the resistor for the IR LED.

Finally, just before enclosing..

The completed project.  Note that I left the mic and IR LED lose because I’m not sure exactly where the alarm is going to be installed and the way they face could matter.

Some lessons learned:

  1. When soldering a header for an LCD remember to take into account that if you copy the wiring order as you have plugged it into the bread-board, you will actually be doing it backwards because the connecter will be attached upside-down!
  2. You will need to drill a little extra hole in your case to accept the tab on the pot that keeps it from rotating when you spin the shaft.
  3. Electret microphones have a polarity.
  4. Hot-glue is great for attaching push-buttons.
  5. Ask you children for UI advice!  Will had the excellent idea of using the setup-pot to spin between the different settings.  In the original code I had it so you had to press the button to toggle between the setup parameters and then do a long-press to actually set one.  The way it ended up is much better.

Parts List:

Arduino Uno: ($29.95)

Makershed Arduino Enclosure: ($15.00)

9V powersupply: ($6.95)

100K Potentiometer: Radioshack ($1.69)

pushbutton switch: Radioshack ($.99)

Breadboard PCB: ($3.00)

Electret Mic: ($1.50)

IR LED: ($.75)

LCD 2×16: ($9.95)

Components: (~$5)

  • resistors: 1k ohm x 2; 100k ohm x 2; 12 ohm; 39k ohm; 22k ohm; 230 ohm (for IR led)
  • capacitors: 470uf 16v; 0.1uf 50v; 22uf 25v
  • Dual op amp IC: TLC272

Total Price: ~$70

clojurescript syntax hilighting in emacs

To get emacs to syntax color clojurescript files (cljs) add this to your .emacs (or other emacs config file):

 (setq auto-mode-alist (cons '("\\.cljs" . clojure-mode) auto-mode-alist))

Upgrading postgres on Snow Leopard (Mac OS X 10.6)

Well, I too have gone down the rabbit hole of having to upgrade compiled-from-source apps to 64bit architecture after moving to Snow Leopard.  The hardest by far was postgres.  The sad thing is that 32bit version works just fine, but the adapter gems for rails don’t, hence the need for the recompile.

Mostly I followed this blog post, but it assumes that you had previously installed postgres using his instructions for Leopard which I hadn’t.

My previous installation was at /usr/local/postgres and these instructions end up installing it at /usr/local/pgsql, so my task also includes getting the data from my previous installation to the new on.

I also took some some hints from this post.

Here’s the blow by blow:

Make a backup of all my data from the 32bit version:

pg_dumpall > /tmp/32-bit-dump.sql

Switch to super user, make a directory for the source (if you haven’t already), download and extract it:

sudo su
mkdir /usr/local/src
cd /usr/local/src
curl -O
tar -zvxf postgresql-8.3.8.tar.gz
rm postgresql-8.3.8.tar.gz

Now configure, make and install it:

cd postgresql-8.3.8
./configure --enable-thread-safety --with-bonjour
make install

Then I followed the instructions from the above mentioned blog on how to make a postgres user, but I did them in a different terminal window because remember the other one we were logged in as root:

“First, you’ll need to find an unused user and group ID. Use the following commands to list the IDs for the users and groups on your system.”

dscl . -list /Groups PrimaryGroupID | awk '{print $2}' | sort -n
dscl . -list /Users UniqueID | awk '{print $2}' | sort -n

“For the purposes of this tutorial, let’s assume an ID of 113 for both the user and the group. Since the convention is to prefix system accounts with an underscore, use the following commands to create a user called _postgres:”

sudo dscl . create /Users/_postgres UniqueID 113
sudo dscl . create /Users/_postgres PrimaryGroupID 113
sudo dscl . create /Users/_postgres NFSHomeDirectory /usr/local/pgsql/
sudo dscl . create /Users/_postgres RealName "PostgreSQL Server"
sudo dscl . create /Users/_postgres Password "*"
sudo dscl . append /Users/_postgres RecordName postgres

“Then, create the _postgres group:”

sudo dscl . create /Groups/_postgres
sudo dscl . create /Groups/_postgres PrimaryGroupID 113
sudo dscl . append /Groups/_postgres RecordName postgres
sudo dscl . create /Groups/_postgres RealName "PostgreSQL Users"

So at this point the binaries are installed and there’s a user to run it under, but I needed to initialize a new database and copy back in my saved data. First create the data and log directories and set perms:

sudo mkdir /usr/local/pgsql/data
sudo chown postgres:postgres /usr/local/pgsql/data
sudo mkdir /usr/local/pgsql/log
sudo chown postgres:postgres /usr/local/pgsql/log

Then I logged in as the _postgres user:

sudo su
su - _postgres

And initialize database files and start up the database:

/usr/local/pgsql/bin/initdb -E UTF8 -D /usr/local/pgsql/data/
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsql/log/postgresql.log start

Finally I restored the data from my initial pg_dumpall

/usr/local/pgsql/bin/psql -U postgres  -f /tmp/32-bit-dump.sql

I’ve also added these lines into my .profile to add the commands to my path and to simplify starting and stopping the database:

export PATH=$PATH:/usr/local/pgsql/bin
export MANPATH=$MANPATH:/usr/local/pgsql/man
alias pg_stop='sudo -u postgres pg_ctl -D /usr/local/pgsql/data stop'
alias pg_start='sudo -u postgres pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/log/posgtres.log start'

And then finally I could install the postgres rails gem (which was the whole point of this silly excercise):

sudo env ARCHFLAGS="-arch x86_64" gem install pg


I was looking at how perl6 is coming along and found this: which is really cool.  Besides being a really nice presentation of the material (including the “Motivation” section) there’s just lotsa nice stuff.  Some of the new way outa here cool perl6 features:

  • meta operators
  • gather/take construct for lazy lists
  • grammars
  • Enums
  • twigils
  • custom operators

And that’s just a few…

Enjoying being on the Wagn

We are building out the new currency frontiers web-site, using the Wagn, which is pretty darn cool. It’s a wiki + database + cms. It’s kinda geeky, but not so much that you have to be a programer to use it (so don’t freak if your aren’t), but if you are a programming inclined, there’s lots of nice stuff you can. Ethan and Lewis are are the excellent chaps wheeling the Wagn. Kudos dudes.

databases and read vs. write consistency

Have just read an excellent blog post on “dumb databases” and the issue of read vs. write consistency. My own mesh & churn for open money comes out of the same realizations that in a distributed environment the way to handle many many issues is to put the responsibility on the reader to verify the validity of the data.

bdd & accounting

I just realized that Behavior Driven Development is very similar to double entry book-keeping in accounting! 

git bandwagon

Well, I’ve officially joined the git bandwagon.  I’ve put metaform up on github (the open money projects will come soon, but I think probably on gitorious); I’ve been reading tons of articles about git; I installed it on Tiger (use MacPorts) and Leopard (install from source with these instructions but use 1.5.5); and now I’m blogging about it.  The most interesting article so far on git, has made me realize how closely related it is to the mesh and churn…  Quite interesting!

ubuntu gutsy on a xen virtual host

Hey googlers looking for tech-support:

I was trying to install various packages (emacs, etc) from universe on Ubuntu Gutsy (7.10), and I kept getting weird segmentation faults (Setting up emacsen-common (1.4.17) Segmentation fault). Turns out that the problem was that my server was being hosted on a VPS running XEN for virtualization, and you have to first install libc6-xen: apt-get install libc6-xen

Hope this saves someone the half day that it cost me…

rails capistrano deploy script OS X to Ubuntu

Ok, so in a previous post I described the rabit-hole which is switching to rails. Below’s my capistrano deploy script which solves a number of problems:

  1. The production server needs a mongrel cluster configuration file added.
  2. Deployment requires restarting the mongrel cluster.
  3. On Ubuntu the database.yaml spec has to be modified to because you need to specify a mysql socket path differently from OS X.

So here’s what I added to make it work:

desc "Restart the web server and mongrel cluster"
task :restart, :roles => :app do
  sudo "echo 'fish'" #bogus command to make sudo work in the run command
  run "cd #{current_path} && sudo mongrel_rails cluster::restart"
  sudo "/usr/local/apache/bin/apachectl graceful"
desc <<-DESC
configure the mongrel cluster
task :configure_mongrel do
  run "cd #{current_path} && mongrel_rails cluster::configure -e
  development -p 9000 -a -P #{shared_path}/pids/
    -c #{current_path} -N 2 --user om --group om"
desc <<-DESC
configure the mongrel cluster
task :configure_database do
  db_config = "#{shared_path}/config/database.yml"
  run "cp #{db_config} #{current_path}/config/database.yml"
desc <<-DESC
after updating we need to add back in the mongrel configuration file so that when restart is called
it will be appropriatly launched.  We also need to update the database config file
task :after_update, :roles => :app do

A “list items won’t wrap” Firefox css fix!

The last few days working on the website, I’ve had a major hassle dealing with what appears to be a bug in the html renderer in Firefox.

The issue is that in Firefox, text in a list item won’t wrap around a right floated image; like this:

  1. Lorem ipsum dolor sit amet, consectetur adipisicing elit,
  2. sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.


<ol style="border: 1px solid #cccccc; width: 300px">
  <img src="/images/eric.png" style="float: right" />
  <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</li>
  <li>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
  ut aliquip ex ea commodo consequat.</li>

In Safari & Opera the text in the second list item wraps just fine. After an hour of searching the web and trying various things with clear, and in-line, I discovered that the solution was to set the list item width to 100%. In other words, list items take on the width that they start at by default! Crazy. The solution:

<ol style="border: 1px solid #cccccc; width: 300px">
  <img src="/images/eric.png" style="float: right" />
  <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</li>
  <li style="width:100%">sed do eiusmod tempor incididunt ut labore et
  dolore magna aliqua.  Ut enim ad minim veniam, quis nostrud exercitation
  ullamco laboris nisi ut aliquip ex ea commodo consequat.</li>

yields nice wrapping text for the second list item:

  1. Lorem ipsum dolor sit amet, consectetur adipisicing elit,
  2. sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

If you aren’t viewing this on Firefox, the above two may look identical. That’s the whole point!

[tags]css,firefox,list item,wrap[/tags]

down the rails rabbit hole

The last month has been quite a trip down the rabbit hole into the new reality of ruby on rails! The promise of a powerful and well designed web application framework was just too much for me to resist, so I decided to leave my own yawaf framework behind (though it has certainly served me well).

So I’m posting this entry for those just starting down this path so you can see what might be on the path ahead of you and what I did to make my way over the learning curve.

  1. I purchased both the Programming Ruby and Agile Web Development with Rails books, and read them cover to cover. Both books are good. Dave Thomas really can write a good programming book.
  2. I dove into finally wrapping my head around the REST approach, which I also knew I wanted to switch to and was part of the reason I choose rails in the first place. To this end I found this great tutorial: RESTful Rails Development which expands on and gives clarity to the REST chapters in Dave Thomas’s book.
  3. Then it was time to install the creature on my PowerBook. The instructions in Dave’s book are pretty good, but the real place to go is hivelogic
  4. Once I had rails up I got my feet wet by implementing the bare essentials of the two projects that are the reason for switching to rails: the MANA stats project and, of course, open money.
  5. Since another reason for switching to rails was to be using an open source framework that others are well familiar with, and because open money is an open source project, and I want to get it out sooner rather than later, it was time to figure out where it should live. I find source-forge unbearably ugly, and though there are some other nice FLOSS platforms (launchpad, freshmeat), I settled on rubyforge for obvious reasons. So I spent a number hours learning my way around rubyforge (an instance of gForge) and setting up the open money project there. I realized pretty quickly that rubyforge is the right place to put up the releases of the projects and I may even use their svn repositories for a while, but gForge doesn’t cut it as a project development environment.
  6. So there I was off into another tunnel of the rabbit hole, which project development tool. So many of them… I see that lots of people, including the rubyonrails folks themselves, use Trac. However, I read many accounts of how difficult it was to install and get running, plus, I really felt that I wanted my project management tool to be in rails, to thereby leverage all my learning curve. I knew also that I was going to be modifying it out the wazoo, so it didn’t make any sense to learn yet another whole system. Dittio for various php bug-trackers, etc. After more hours of research, my options were then down to three: collaboa, retrospectiva (which is a fork of collaboa), and devalot. The first two are much more feature rich. But I ended up choosing Devalot, after talking with it’s author, Peter Jones (who seems like a real great guy) mostly because it just feels better than the others, but also because I like where it’s headed.
  7. Then I started to scratch my head about how in the heck I was going to deploy these apps. Yawaf is Perl base and deployable as plain CGI and works quite well for small sites. I’ve always known that I could switch to mod_perl if traffic increased enough to warrant it. Rails is another matter. You need to start out understanding deployment.
  8. So I read all that I could find, and tagged the good stuff for your reading pleasure on delicious. Upshot for me is apache 2.2.4 + mongrel + mod_prox_balancer + monit (not mongrel_cluster). [Update, after many hassles with monit, I ended up going back to mongrel_cluster (though I may add monit in later to monitor the cluster). See this e-mail exchange on the mongrel-users mailing list for details.]
  9. Then I realized that getting this to happen on my current VPS was going to be a nightmare, because it’s a DirectAdmin box, and getting apache upgraded to 2.2.4 was hard enough, but adding mod_proxy, etc was just not going to be doable while at the same time keeping it stable with my current apps live.
  10. So, then it was deeper down the rabbit hole into investigating Rails Hosting companies! Finding a hosting company in general is a huge pain and it is so variable according to your needs. Mine are complete control, hence VPS. Upshot: the company I wanted to go with, slicehost, is only taking reservations, and can’t fulfill orders for a month. Yow. (By the way, here’s a great writeup on rails hosting, and more delicious tagging of rails hosting in general.)
  11. So, now I’ve decided to do all this installation and testing of my future deployment environment on my basement Ubuntu server until slicehost comes through, or I find something better. For Ubuntu installation I’m taking some hints from these instructions which were missing one dependency for apache to compile for me (sudo apt-get install openssl libssl-dev). You may also want to check out this peepcode screen cast for another take on how to install the rails stack onto Ubuntu using deprec. It turned
  12. Once all the components are installed, the next challenge is configuring them to work right for your particular rails app. Enter bowtie, also by Peter Jones. Though still in development, this little utility produces configuration files for apache to use mod_proxy_balancer, and also for monit to launch and keep your mongrel instances up and running.
  13. Ok, so server is up and running, and I have a basic app on my development box, now I how do I deploy to the production server. Enter capistrano. Yet another learning curve. The trick is getting your deploy.rb script right to handle all the various problems… That will wait for a future post.
  14. Then, back into coding, I’ve realized that I just have to bite the bullet and start to use all the goodies built into ruby and rails for doing test driven development. So I started doing some background reading on good TDD practices which led me to behavior driven development which of course is why I’ve been putting of using TDD for so long because it’s BDD that actually makes sense. Here’s a great article by Dave Astels on BDD in the Ruby context. And fortunately there is rspec, a great implementation of BDD that integrates well into rails. The tutorial in the rspec documentation is very good for understanding it, and here’s the tutorial I used to get started using rspec in the rails context. Which led me to another helpful post by Dave Astels.

SnapMail on Seth Godin’s Blog

So marketing blogger Seth Godin has a mention of SnapMail in the same breath as File Maker Pro on his blog. It’s nice that my humble little program is in such august company, though the context is a bit sad. What’s so odd is how SnapMail was created before the Internet was at all a house-hold word, back in 93, and it still has such a faithful following. I guess there is something valuable about having a little communication tool that’s not on the Internet! Who’da a thunk?


another currency metaphor

In my on-going quest for good metaphors and ways of thinking about the community/multi-currency world, an excellent metaphor came to me that is useful when talking about all this with programmers:

federal currency = global variables
community currency = local variables

Writing software with only global variables is not impossible, but their “liquidity” (i.e. the fact that they have “value” everywhere) is not an asset, but a liability. Of course an individual variable “loses power” by not being “valuable” everywhere, but its utitlity increases by being only have value in a given context.

The whole programming concept of “scoping” applies to currency!

[tags]currency, programming, scope, community currency, local variable, global variable, money, metaphor[/tags]

Phronesis and the Internet: the Process Revolution

I learned about the Aristotelean intellectual virtue of phronesis along with the related term episteme a few years back from Kathryn Montgomery in discussions about her book How Doctors Think. Episteme is the scientific rationality we are all quite familiar with. Phronesis is usually translated “practical wisdom” and is the kind of rational skill doctors and entrepreneurs have that is based on experiential knowledge and provides the ability to take the best action in particular circumstances. We are much less likely to have thought of this as a separate kind of rational capacity.
These terms came up again recently for me in the context of a collective intelligence discussion, which really set my mind going and has led me to some propositions and a conjecture:

Proposition: Whereas the printing press was an episteme engine, the Internet is a phronesis engine.
Alternative long phrasing: The printing press and the Internet are cognitive technologies that provide people and cultures with “mechanical advantage” or leverage for the development of the Aristotelean intellectual virtues of epistome and phronesis respectively.

It’s pretty easy to see how the printing press is responsible for the massive scaling of epistome into the general culture. It’s a bit harder to see how what the Internet is doing is the same for phronesis because our first viewing of the Internet (the web at least) has been that it’s just one giant sales brochure/advertising billboard/encyclopedia/etc, i.e. that it is a global source of knowledge. My proposition is that the key thing going on with the Internet is not access to knowledge, but rather access participation in knowledge processes. Three examples:

  1. Wikipedia. What really matters about it is not that we have access to a massive knowledge font, but rather that each of us can become encyclopedists and have to face the questions of ontological classification, neutral voice, objective/subjective reality, etc, that that entails.
  2. Blogs. A word perhaps for at least three information processes moved out mass culture: journalism, publishing, political analysis. Again the key shift is not that there is all this reporting/publishing/political analysis available for our consumption, but that that each of us can become journalists/publishers/political analysts.
  3. My own online-writing workshop. People come to the site thinking that they will get reviews of their writing which will improve it. They invariably discover that reviewing the work of others is how they end up learning to improve their own writing.

In each of these cases the key thing is the shift from access to static information, to active participation in an information process. The Internet is providing a “mechanical advantage” for putting people together in a place where they can jointly engage in the kind of information processes and processing that I think leads to the developing of phronesis.

Proposition: Economic revolutions occur when aspects of production are sufficiently amplified by cognitive technologies that new economic patterns of production come into being. Example: the printing press provided the intellectual infrastructure (a culture of epistome) for the expansion of the simple tools of production during the industrial revolution into what is called Capital in the classical economic sense.

Proposition: There is a new economic revolution under way, the Process Revolution, that is the result of the amplification of information and information processing by the cognitive technology of the Internet, and which is similarly bringing new economic patterns of production into being. These patterns are a new economic factor that can be called Information (capital I), which is defined (analogously to Capital) as the data plus the patterns and processes that use that data to organize production.

Proposition: New economic factors produce competing political systems that are answers to the question: who should own the new economic factor. Example: In the industrial revolution the question was: who should own Capital and the products produced by Capital. Communism proposes common ownership in the form of the State, and Capitalism proposes ownership by individuals.

Proposition: The new economic factor of Information is likewise producing competing approaches to answer who should own it. “Ownerism” which proposes the same answer as Capitalism (ownership by individuals, natural or corporate), and “Commonism” which proposes that its ownership be held in the commons (not by the State).

Proposition: Capitalism won out against Communism for three fundamental philosophical and systemic reasons:

  1. Capitalism was better at recognizing and building on individual dignity and potential.
  2. Capitalism is essentially decentralist because it pushes the intelligence out to the edges (see David Reed & Andrew Lippman’s paper on Viral Communication for details on this idea) where local information can be used to maximum advantage in decision making.
  3. Capitalism works with, not against people’s natural self-interest.

Conjecture: Commonism will win out over Ownersim because it shares with Capitalism the same first two properties as well as another property which is analogous to the third, namely that Commonism works with Information’s natural abundance and it’s tendency to flow everywhere, whereas Ownerism has to fight tooth and nail to keep it scarce and from getting out.

I’ve put together a more detailed presentation of these ideas (including their relation to money) in the form of a paper.

simple shared state protocol

Recently it hit me that I knew of no generalized protocol for sharing the state of an abstract space among a group of computers. I did a quick google search to see if I could find anything, and after coming up dry (which doesn’t mean it doesn’t exist) I decided to slap one together to test out the many uses for this that were readily apparent to me (i.e. any application where multiple users must be able to collaboratively make changes, and become aware of changes made to that space in real time: chat, bulletin boards, network games, etc.)
Of course there is similar stuff like Croquet that certainly does an even more complicated generalized version of this, and lots of single purpose applications, like Subethaedit which must also do thisbut I haven’t found other efforts that are quite as simplistic and generalized.
So, I slapped together the beginings of a protocol as well as a ruby based server, and a RealBasic based clients for OS X and Win to test out the ideas, all of which are released under the GPL license.