AIR app – user idle detection

Wednesday, March 14th, 2012

Found out that it is super easy to deal with timeouts…i.e. when you create kiosk applications, you generally want the activity to timeout and go to some sort of attract screen or activity reset when no one has touched the screen, move the mouse or press the keyboard.

There’s the NativeApplication class for AIR to the rescue:

/* this is in seconds */
NativeApplication.nativeApplication.idleThreshold = 60;
NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, handleUserIdle);
NativeApplication.nativeApplication.addEventListener(Event.USER_PRESENT, handleUserPresent);

private function handleUserIdle (e:Event) : void
  //reset activity
  //show attract screen

private function handleUserPresent (e:Event) : void
  trace("There's a user!");
  //hide attract screen

AS3 – messaging between objects, a decoupled approach

Sunday, February 12th, 2012

I’m working on an interactive installation. I’m building a couple of AIR apps. A really useful object that I’ve worked with in the past is a Broadcaster. Think of it as the telephone operator of old…you know the kind at a switchboard that actually has to connect a wire between the two callers. Well, the Broadcaster is great for keeping objects decoupled from each other. Typically if you want to send message between objects, each object has to somehow know the existence of the other object. You do this by keeping a reference to it.

//This is inside the sender class
// save a reference to the receiver
// so we can tell it to do something later
var receiver;
receiver = {the_receiver_object};

With the Broadcaster class, you just tell the Broadcaster that you’re interested in a certain message. Any object in your application can fire that message. Once that is fired, you get an event and it’s up to your class to handle it.

// in the receiver class
// when we receive the "RESET" message,
// run the reset_activity() function.
Broadcaster.subscribe( "RESET", this.reset_activity );

function reset_activity ( e:RichEvent ) {
//do something

// in the sender class
// fire off the "RESET" message
// and also pass along some parameters "RESET" , {transition:"fade_out"} );


Notice that neither class has any knowledge of the other class. They are really just ‘connected’ by the message that they are firing and listening to.

The beauty of this is that any class can fire a message and any class can listen(subscribe) to that message. The Broadcaster does the routing between sender and receiver just like the old telephone switchboard days!

Here’s the awesome minair library that has the Broadcaster class. If you just want to use this messaging architecture you’ll need to grab the Broadcaster, RichEvent, and the Log classes. Good luck!

Configuring git to ignore certain files

Friday, February 10th, 2012

I’ve been working with git on and off for about a month now. I’m on a Mac and git always picks up changes to the .DS_Store files within directories. Also when working with XCode, it picks up changes to the user workspace files, etc.

There are a few ways to tell git to ignore these files and not keep them under version control…mainly:

  1. putting a .gitignore file in a directory and listing filenames and/or filename patterns to ignore – this can be checked in just like any other file. The effect is that anyone that clones your directory also will ignore these files.
  2. entering the filenames and/or filename patterns to the .git/info/exclude file in your local repo – only affects your local repo
  3. running the command git config –global core.excludesfile ~/.gitignore_global (.gitignore_global is a file where you specify the ignore patterns) to globally ignore certain files (see the link above fore more details) – I haven’t tried this yet, but this seems great so that you don’t have to re-specify which files to ignore every time you work with a git repo


Tool for Marine Biologist

Sunday, January 15th, 2012

My brother-in-law is a marine biologist and he often will do ocean surveys as a contractor. Recently, he did a survey to measure the amount of eel grass in a certain area. The way that he does this is via scuba and a GPS unit. He essentially gathers data, in a methodical way (I’ll spare you the details), and then uses the data to generate a black & white pixel map. Black areas indicate that eel grass is present. He then usually brings this map into a really expensive software to calculate the total area of eel grass.

I recently happened to be tooling around in Processing and decided to make a very quick and dirty tool to do this calculation. You run this program, pick the image, set the pixel measurement for your area unit, and the software will tell you how many area units you image contains. The interface is not pretty…just functional.

Moving Time Machine backups to a bigger drive

Thursday, January 5th, 2012

I have a drive with 3 partitions (The Big One, Rachel Time Machine, James Time Machine). I had quite an ordeal trying to moving each TM backup to a new/bigger drive. Initially I tried doing a straight copy from the File Manager…i.e. just dragging the Backups.backupdb directory to the new drive. It worked for Rachel Time Machine (took probably 3 or 4 hours). (I also found out that doing a straight file copy essentially is not efficient because doesn’t preserve the links (logical pointers to files) but essentially duplicates the file that the links are pointing to (see patrix’s comments in the link above). After copying the files over, I pointed Rachel’s laptop to use the her new Time Machine drive and I can see all of the older backups. Great!

Migrating James Time Machine to a new drive was not so smooth. Doing a straight file copy took forever (something like 5 to 6 hours)…I basically let it run over night. In the morning I woke up to find that it didn’t work. Here’s the ordeal described for a Stack Exchange post. As you can see from the post, trying to copy using OSX’s Disk Utility didn’t really work the way I wanted to. It basically cloned my drive so that my NEW drive was just as small as my original (I think it basically created a small partition…but the weird thing is that if you look at the disk in Disk Utility, there is only one partition and it should be 1TB, the size of the new drive…hmmm). Carbon Clone Copy didn’t work either. Finally SuperDuper! did the trick!!!

I have to thank this Neil’s Apple Blog post for mitigating some of the frustration along the way…it was comforting to see someone else with the same issue and that a solution was possible!

Stanford AI Class

Thursday, November 17th, 2011

I’m taking the Stanford AI Class, which started about 6 weeks ago. It’s been eye opening and it’s also a welcomed challenge. This is essentially an online version of the AI class that they teach at Stanford. This is the first time that they are trying an online version that is open to all. They have over 85,000 students enrolled. I’m a bit behind on the lectures because of the arrival of baby Maya. So, I should stop blogging and get back to the class!

‘Making’ again

Monday, November 14th, 2011

Just started playing around with Cinder. It’s along the lines of Processing and openFrameworks. These platforms, if you will, really helps with the creation of graphic and event-based applications. I’ve worked with Processing (taught a class), dabbled in openFrameworks (created a music exploration/visualization environment) and am now trying Cinder.

For Spring 2003, I created a class called Dynamic Bodies at ITP. The class helped students to create algorithmically controlled/animated objects using vector math and physics. It was a class I created out of a labor of love and inspired by folks coming out of the, then John Maeda led, Aesthetic Computing Group. Some of the things that I’ve taught in that class have now been made easier with the introduction of libraries for vector math, physics engine and algorithmic behaviors (such as for boids). Many of these libraries are available for the three platforms above; one of the more notable is the feature rich toxilibs by Karsten “toxi” Schmidt for the Processing platform.

I missed those days of making things so I’m taking this opportunity to get back on it! One other reason for this step towards ‘making’ is that both openFrameworks and Cinder can be used to build iOS apps. I have an iOS project ‘in the works’ with a friend.

Trying to write my first iOS app

Friday, October 7th, 2011

MY friend Jenna and I have been brainstorming about a kids’ iOS app and I’m finally excited about making what we’ve schemed up happen. It’s going to be an iOS app that needs a physics engine.

It turns out that cocos2D for iphone is a sprite based game engine. It now includes integration with the Box2D physics engine. Both cocos2d and Box2d are free to use and distribute with your app.

This should be really helpful for our idea…stay tuned.

e-commerce project

Friday, September 23rd, 2011

We’re finally moving ahead with an e-commerce project. It’ll be very exciting with lots of new things to deal with…like Merchant Accounts and Payment Gateways. There are so many out there. We’re using BigCommerce, a cloud ecommerce offering, which integrates with many payment gateways so I won’t have to code anything…but it’s not making it any easier to select one.

This is a good “how it works” diagram of payment gateways and merchant accounts.

Our client is a brick and mortar store that current swipes physical cards at credit card terminals and they also take phone orders. So I’m trying to figure out what merchant account(s) they need and what payment gateways(s) they need…and decide which providers would allow for the most flexible configuration. Another thing that I needed to consider is that they’re currently shopping around for a new merchant account but our ecommerce store won’t be launching for at least a few months. So, the providers should allow us to grow the business and add the ecommerce store later.


Merchant Accounts

Depending on the merchant account provider, you’ll have to sign up for at least one, if not many, merchant account based on how you will be receiving payment. The company that our client is looking at, Elavon, requires a merchant account for retail (physical card swipes), MOTO (mail order/telephone order), and ecommerce. Needless to say, each account costs money…for setup, per transaction, has monthly fees, etc.

Payment Gateway

In order for you to process and connect to your merchant account(s), you will need at least one payment gateway, if not more, to connect to each of your merchant accounts. So you may need a retail payment gateway to process and connect to your retail merchant account, or you may need an ecommerce payment gateway to process and connect to your ecommerce merchant account.


One of the gateways on the BigCommerce list of partners they integrate with is PayLeap. They actually have a plan called “Brick and Click” which essentially allows you to process transactions originating from retail, MOTO, and ecocmmerce, under ONE merchant account and ONE payment gateway. Also their fee structure seems really reasonable. So, as of now, I’m recommending this to our client.

Learning Python

Friday, December 17th, 2010

Just had drinks with Justin and Scott last night at the Brooklyn Inn. We geeked out and now I’m going to try to learn python again. Found this article, by Red Sweater, about learning python using the mac. They made a little app that contains a web browser in one pane and a terminal in the other. The web browser points to the python tutorial page written by Guido van Rossum (the author of Python).
The article mentions Nodebox…a Processing like environment which uses Python as the language. Cool!