You are currently browsing the category archive for the ‘Uncategorized’ category.

This would have been a tweet but has snowballed beyond its 140 char limits into a definite POST.

Twitter has been offline for the last 40minutes, and I really wanted to blip / tweet / ping the world that I had been enjoying some things…

Enjoyments

Have been enjoying the following without any guilt whatsoever :

– ‘religulous‘ doco last nite, very irreverend, very entertaining

– ‘Rereading Darwin‘ – still radical & relevant if we can grok eon sized time-spans

– web based interactive graphing calculator : www.abettercalculator.com

These are all awesome things, relying as they do on the advances that can be made when young people have freedom to think, to learn, have access to books and mentors and dont need to spend all their time either at war or gathering food or preparing shelter.

Decentralise!

So that was going to be the basis of my tweet, but that has been subverted into a rant on why Twitter, and Facebook, and Foursquare and LinkedIn and… are fundamentally wrong, whereas the Internet is fundamentally right.

Twitter and Facebook etc. [or the social networking needs they serve] should really be implemented as a distributed system. Each person or a cluster of people would have a local server ‘node’, and it would route messages to other nodes and so on.

For popular tweets or status updates, or checkins or wall postings there would be thousands of copies of that tweet sitting on servers all over the globe. This redundancy is a good thing, there would be less chance that a single Denial of Service attack or plain old human error or of a hardware failure or a mass event taking down the whole system. It could also mean we have more control of our own data – we should ‘own’ the posts we make, and the company we pay [ in advertising or in cash ] would provide the plumbing for the routing of messages and content.

This kind of distributed agent approach requires us to grow psychologically beyond the need for a ‘Central Authority’.. in fact I think that the technology will eventually take us forward to better forms of government, security and privacy, in that they are less centralised, more efficiently optimised to the local and the global environment – fundamentally they will offer more freedom and may require more responsibility.

Parse.com is a Y-combinator startup offering a fest-setup and easy -to-use backend store for iOS and web apps …

Here are some impressions after using on a commercial iPhone app project :

My feedback after using Parse for real work for a few days on iOS is that there are a few things that Id like to see added :

  • allow Pointer type cols [aka relations / object refs ] to be added via the web / DataBrowser
  • allow double click on objectIDs in DataBrowser, for ctrl-C/V
  • add csv export, json export [ imnso, these make me more likely to pay for Parse, not less ]
  • search/filter, sort cols, in DataBrowser

As a workaround I had to do “inspect element” of the Data Browser web page to get the object id, then write some test code to create the object Pointer references.

 

Also Ive been pining for a detail button for each row – that would pull up a detail grid with [ colname | value ] so I can see all a rows attributes vertically at a glance [ if it can be left open while I select rows, all the better ]

Generally, the iOS Parse api is nice, and it just works… in fact a lot of this I had already implemented myself in js + Node.js + mongo, but a client wanted a Parse backend so that gave me an excuse to evaluate.

So my first impression is good, but as people use this for real work, youll need those little details to save time.

( btw, prefetch link/reference with includeKey is handy )

Been using git more and more for public hacking and private consulting work.

Some impressions / notes –

  • github.com is superb!  Radically better/simpler/easier/nicer than sourceforge or google code
  • I lurrve code snippets, aka GISTs hosted on github. Sane blogs support inline gists [ not wordpress.com, yet ]
  • Found a clear readable tutorial on setting up a remote git repo (with git and gitosis) for private or public use
  • Github is so nice, its really tempting to just pay them money for some private repos rather than step thru the above
  • A handy git meta- cheat sheet here

NPM Module

So that we can reuse the simple serialq code from the previous blog post, I have tidied things up and packaged into an NPM module.Apparently its now installable using “npm install serialq”.

Creating the module was a breeze –

  • within your directory run ‘npm install’ and fill in the questions
  • npm adduser, npm publish
  • test with npm install

After publishing, the module magically shows up on the extremely handy npm.mape.me module search site, under keyword ‘serial’.  See isaacs article ‘How to Module‘ for overview.

Code

The code is a bit simpler to read, as you can see its a very short implementation :

exports.SerialQueue = function()
{
    var sq = 
    {
        funcs : [],
        next : function()
        {
            var Q = this;
            var f = Q.funcs.shift();
            if (f)
                f(function() {Q.next();});    
        },
        add : function(f)
        {
            this.funcs.push(f);
        },
        run : function()
        {
            this.next();
        }
    };
    return sq;
}

Usage :

    var Q = SerialQueue();
    Q.add(fn_first);
    Q.add(fn_second);
    Q.run();</code>

[ For a more readable version of the code snippets above, see this github Gist. Would be nice if wordpress.com supported Gists, Posterous do..ahh maybe time to move my blog. ]

Thoughts

I found this module handy for serializing access to a mysql database. Breaking out this boilerplate made the rest of the code clearer.  Code is up on github

Surprisingly Javascript + Node.js is a real workhorse.  I actually prefer it to Perl/PHP and even Ruby/Python for data plumbing tasks.  You have hashmaps and regex handling built in, garbage collection, and a superb general purpose data format in JSON.  Perhaps Javascript is the hundred-year-language?

Be aware this is ‘cooperative’ sequencing.. each function gets passed a done or next argument, and will have to invoke that to signal completion [ causing the next function to be run ].

Some reading links –

  • HN style forum of quant posts – quant.ly
  • High Frequency Trading articles are here
  • Herb Sutters Effective Concurrency articles from Dr Dobbs Journal are here
  • Herb Sutters Blog – Sutters Mill
  • Fun talk on C++ – vid here [If the goal of C++ is ‘high-performance-abstraction’ has it succeeded? ]

Rhetorical question – given that only three people on the planet truly understand the subtleties of C++ … is this a language anyone should be using to build reliable software?    C++Ox is nearing completion, so the language continues to grow in size.

Custom UI

I see a lot of interest in custom UI for iPad.   There are wonderful interactive books such as Alice and Im sure well see some very interesting interactive comics and graphic novels come out for the platform this Christmas.

Some brands have a certain graphic look and feel that is distinctive and they want to preserve that instead of the Apple ‘native’ look.   Other clients want a native looking app done in HTML5 delivered faster than an approval process would allow.

I recently developed an iPad app for an US based startup company.  The app gathers medical data at the scene of an emergency, and the designer came up with some excellent visual motifs, mixed in with traditional native UI elements.

Ive tended to develop custom UI in native Cocoa until this point, but the technology has been there for a while, as evidenced by apples own PastryKit.  Now there are several good frameworks like jQTouch, Sencha and jQueryMobile, but more importantly one can google for the grab-bag of techniques and examples that showcase the power of accelerated webkit animations.

iPad Demo

For a clickable early version of the app, open this link in Safari on iPad or Safari on Mac – iPad Demo

[ chrome on Linux will also work, for example, as it too is webkit under the hood ]

As you can see Ive implemented boolean [ ON | OFF ] slide toggle switches using an alpha mask and webkit transitions – pretty much any native UI is doable.

Impressions

I continue to enjoy the lisp-ness of Javascript.

Javascript + CSS + HTML divs + nice GPU accelerated animated transitions = superb prototyping environment.

The other win is that my code seems a _lot_ smaller than if I did this in Cocoa / Objective C.  I’m not knocking UIKit / iOS, the APIs are generally excellent.. but they are verbose in comparison.

The native look and feel and immediate response is achievable [ make sure you implement touchstart and don’t rely on the click event or your user will be waiting 250ms for the UI to respond… ]

Interesting times.

Maps

I prototype a number of techniques to deliver interactive floor maps.

Here is a floor plan of the main area of Melbourne Central, a popular shopping area in the CBD.  Created with SVG + javascript so will only run in Browsers that understand SVG.

Melbourne Central Map SVG

These kind of maps would be very useful navigating large Expos, so here are some demos…

Standard divs approach :

Home Garden Show

Fashion Exposed

SVG versions, for modern browsers only  :

Home Garden Show

Fashion Exposed

Impressions

All in all SVG is an incredible format for these kinds of graphics, and I think well see a lot more interactive books, comics and StarTrek inspired custom UIs developed in SVG.   Its a sane way to deliver to iPhone, iPad and various Android screen sizes with  common code base and one set of graphics assets.

After many years of neglect and non-standards-compliance, I’m looking forward to seeing the upcoming IE9 release of Internet Explorer browser with accelerated graphics and native SVG support.  Graphic designers will be set free to create and developers will be empowered to push the boundaries of the web to the next level.

Lately I seem to be busy mainly with consulting to Internet and Mobile startups, and one of the things I get asked a lot is which technologies I recommend for a given project.

It seems to work best when I give two approaches to serving data, one based on newer tools such as Node.js and CouchDB along with a more conservative alternative using Ruby on Rails or traditional LAMP stack as underlying technology.

As a prelude to the detailed project plan and data design, I usually give an overview of current trends.. I get asked that a lot, so I thought Id put my observations online here as a few bullet points :

Technology Trends :

  • Web and Mobile projects are converging [one usually implies the other]
  • Most data is social data [for the user and the people they interact with]
  • Most data naturally fits a tree or graph structure [tabular, not so much]
  • JSON has replaced XML [hand-in-glove with web, iPhone, Android ]
  • Scalability is a feature [can be deferred, but no easy migration path]
  • The days of generating HTML from PHP are gone [use JSON feed + jQuery]
  • People still use PHP and MySQL [it works, you can find developers]
  • Code using MVC frameworks tends to be overly verbose [Zend, Rails, Django]
  • Node.js and CouchDB are cool [but the newness of NoSQL is risky]

These are universally accepted as a good thing :

  • iPhone vs Android : both are good, competition is great!
  • JSON
  • jQuery
  • Architecture :  [ server data store ] <–> [ JSON ] <–> [ Web / Mobile client ]
  • AppStore revenue model

These are technologies to watch for :

  • Node.js [ultra high performance app servers can be written in Javascript ]
  • CouchDB [scalable NoSQL with sane REST api, map/reduce in Javascript ]
  • SVG [allows new kinds of User Interface on web & mobile ]

The above observations and predictions raise some interesting questions.. but Ill save that as juice for another post.

I’ve been thoroughly enjoying Paul Zeitz’s book “The Art and Craft of Problem Solving“.

One of the early problems in the book is from 1994 Putnam math competition, but surprisingly easy once you see that it can be scaled into a much simpler question.

The problem :

Find the positive value of m such that the area enclosed by the ellipse x^2/9 + y^2=1, the x-axis, and the line y=2x/3 is equal to the area in the first quadrant enclosed by the ellipse x^2/9 + y^2=1, the y-axis, and the line y=mx.

Heres a drawing of the areas mentioned using GeoGebra, with each area in separate quadrants for comparison, with an approximate area.  The Qn asks what is the slope of the line through point F [or -ve slope of line through Q here].

Problem as stated, with areas colored

Well its a bit hard to pick the point Q [ the slope -m ] so that these colored regions have the same area…

… but then you realize that the whole problem becomes easy if you simply scale the ellipse back to the unit circle.

To do this, x is scaled back by 3x, so areas become 1/3 of what they were [y remains the same].  So the problem now looks like this :

“]

scaled back to the unit circle : areas are x 1/3, slopes x 3

So the line that gives the same area is y=x/2.  When this is scaled back to the original ellipse, the slope gets divided by 3;  so the line we want is y=x/6.

Quite surprised to see this in a Putnam, but it does show a really common motif in math, namely :

Transform to a simpler domain, solve it there, then transform the solution back.

The astute reader will have noticed that I cheated : the areas of the colored regions in the top picture are of course ~1.65 or 3 x area of regions in the second diagram.

The areas marked were calculated by rough approximation with a polygon and the GeoGebra area function. [  The ellipse itself was drawn to fit using foci – I wasn’t sure how to edit the formula in GeoGebra to make it exact. ]

I’ve added a secondary ‘slave’ circle, which I think introduces the idea of Fourier series in a natural way.

The animation starts as before with a sine curve,  then you can add in the second circle by clicking ‘toggle’.

Click this picture to see the Javascript web animation :