Harry Tormey

May 3, 2010

Developing an Android application using the Snaptic API

Filed under: Android, Java, Programming, Snaptic, Technology — Tags: , — admin @ 6:26 pm
As part of the Snaptic Move Your App! Developer Challenge you are required to use the Snaptic API to create an Android app which encourages and tracks physical movement. Currently their are two ways to do this: Either by using intents to save data via 3banana notes or by including the Snaptic android-lib in your project.

The advantage of the first approach is that you have to do a minimum amount of work to push/pull notes and accompanying information from the Snaptic backend. The disadvantage is that you now have a dependency on 3banana notes which must be installed in order for you to access any stored information. Integrating using the Snaptic android-lib gets rid of this dependency and allows you to communicate directly with the backend. For instructions on how to integrate with 3banana notes using intents go here, the rest of this article will cover how to integrate using the Snaptic android-lib.

The following is a little cooking demo which will show you how to create a basic app which can post and fetch notes from a Snaptic account.

  1. Download the Snaptic android-lib project from git hub.
  2. Create a new Android project using the instructions outlined in the following hello world tutorial.
  3. Copy the src for com.android.http.multipart and com.snaptic.api into your project from Snaptic android-lib.
  4. Add the commons-codec-1.4.jar to your project (included in the android-lib lib directory), see this tutorial for instructions on how to add libraries with eclipse.
  5. Add the internet permission to your Hello World manifest xml file, for details on how to do this see here.
  6. Now add the following to your HelloAndroid activity in order to be able to post/get notes:
 Java |  copy code |? 
01
   	
02
   String LOGNAME = "HELLO_SNAPTIC";
03
   Boolean DEBUG = true; 	
04
   String mUsername = "";//Add your username here
05
   String mPassword = "";//Add your password here
06
   SnapticAPI mApi   = new SnapticAPI(mUsername, mPassword);
07
 
08
   //To post a note
09
 
10
   //Create a note 
11
   SnapticNote note = new SnapticNote();
12
 
13
   //Set the attributes you cate about
14
   note.text = "Post this notes";
15
   int returnCode = mApi.addNote(note); 
16
 
17
   if(returnCode != SnapticAPI.RESULT_OK){
18
      //Log Error
19
      if(DEBUG)Log.d(LOGNAME, "Notes Error: " + SnapticAPI.resultToString(returnCode));
20
   }
21
 
22
   //Grab all notes from the account.
23
 
24
   //Create an array list to hold notes
25
   ArrayList<SnapticNote> notes = new ArrayList<SnapticNote>();
26
 
27
   //Call get notes
28
   returnCode = mApi.getNotes(notes);
29
 
30
   if(returnCode != SnapticAPI.RESULT_OK){
31
      //Log error 
32
      if(DEBUG)Log.d(LOGNAME, "Notes Error: " + SnapticAPI.resultToString(returnCode));
33
   }
34
 
35
   //Iterate over notes and do what you want with the note attributes
36
   for(SnapticNote n : notes){
37
      if(DEBUG)Log.d(LOGNAME, "Note text" + n.text);
38
   }
39
For a more advanced example app which uses the Snaptic android-lib checkout the open source crossfit tracking app I wrote here. Also the javadocs for the Snaptic android-lib can be found here.

April 5, 2010

First thoughts on the IPad

Filed under: Interesting, Review, Technology — Tags: — admin @ 8:28 pm
Initial thoughts on using the IPad. It feels significantly heavier than a kindle and holding one for protracted periods of time is a bit tiring on the wrists. Looks way better in real life than in pictures (bezels = not photogenic). Keyboard is a pain in the ass to use and requires the device to be tilted. Multi touch is super sexy and the device feels quite snappy and responsive. Overall using the device was a very fun experience.

Apps: Tried out Omnigraffle (awesome graphing tool for mac), felt a bit unresponsive and cumbersome at times but generally was fun to play with. Snaptic’s (company I now work for) 3banana note taking app is pretty cool, the changes made to the pad version for launch make it easier to navigate through your notes. Tried out Y! entertainment app, was pretty fun but not really my cup of tea as I bought hate tv guides and reading entertainment news (transitions looked sexy though, fun coffee table for your mum/girlfriend).

If I was an average user would I buy one? No. Seems like a decent first gen apple product and I can see a lot of fun media related products being written for it. I think for the average person the lack of a camera and a wide selection of mature multi touch software is a deal breaker. I do think developers should totally grab one right away as their is a lot of potential for this device once apple smoothes out some of the rough edges and a bunch of great software emerges. Several IPad’s are lying round my office so of course I will be hacking on them. It will be interesting to see how this device will stack up to the armada of android/windows 7 clones that are going to hit the market in the coming months.

October 4, 2009

PyGameSF meetup Thursday October 8th 6pm @ 3rd floor Main San Francisco Public Library

Filed under: Facebook, Interesting, Programming, Pylons, Python, Social Networks, Technology — Tags: — admin @ 9:59 pm
The October PyGameSF meet up will be at the PALEY (not the STONG) conference room on the third floor of the main San Francisco public library besidecivic center BART. The library closes at 8pm so we will reconvene to frjtz on hayes street for dinner/drinks afterwords.This month’s presentations are:

  • Shannon -jj Behrens, How to Blow Up Helicopters Using Pygame. The talk will consists of a summary of some of the libraries and tricks JJ used for his two PyWeek entries. It will be covering topics such as PGU, generator-based animations, and state machine based levels.
  • Harry Tormey, Who is it? This talk will cover the in’s and outs of working with Facbook and pylons while giving an update on a social network game I am currently working on. (This talk will cover a lot of the material skipped over in the August presentation)

    JqueryTwitter: A simple Twitter Pylons example using Jquery and python-twitter

    Being able to write applications for facebook is nice but if you really want to be all hip and buzzword 2.0 compliant you need to be able to add ajax and Twitter to your repertoire. With this in mind I decided to put together a simple little demo which uses Jquery/python-twitter to scrape, search and update a list from the twitter public time line in “real time” every time you type a letter in a text box. You can grab the source here.

    In times of yore developing any web application involving Javascript meant wading through a sewer of browser incompatabilites and crafting inelegant hacks to deal with the fact that the majority of people surf the web using old non standards compliant web browsers (i.e internet explorer 6). To add insult to injury the tools available for developing Javascript back in those ancient times totally sucked.

    Fast forward to 2009 and we have awesome debugging tools like firebug and webkit inspector which make web development a somewhat more manigable proposition. Apart from nicer debugging tools the Javascript scene has been flooded with a wave of sweet libraries (mochikit, yui, Jquery, etc) all designed to abstract away common tasks and annoyances (browser incompatabilities I’m looking at you). Add to all of this the recent focus by brower makers on Javascript performance (v8, JavaScriptCore, etc) and you will find that developing Javascript today is incomparably nicer than in the bad old days.

    Most of the secret ajax sauce that powers this example can be found in demo/public/search.js. My library of choice for this project is Jquery, which I picked due to the fact that there has been a ton of plugins written for it, it’s been around since 2006 and is very straight forward to use.

    The application comes bundled with Jquery and python-twitter. It assumes a basic familiarity with both Javascript/Jquery, that you have read chapter two and three of the excellent freely available pylons book and or that you know your way around Pylons. Unlike my facebook example this demo should serve straight out of the box (after you serve up development.ini with paster visit http://127.0.0.1:5330/search/index). Enjoy.

    October 1, 2009

    HelloPylons: A hello world example for Facebook using Pylons and PyFacebook

    As a follow up to my talk at the PyWebSF meet up I decided to put together a “hello world” style facebook app. The goal of the app is to illustrate clearly the relationship between what gets displayed on your facebook app’s canvas page and what get’s sent back to the sever hosting your app via it’s facebook callback. You can download this application here. To reiterate some points I made in my presentation, the basic flow of a facebook application is like so:

    • Someone visits your application (i.e http://apps.facebook.com/yourapp/), what they see is the canvas.
    • Visiting the canvas causes facebook to makes a callback to your application (i.e http://www.harryisawesome.com/yourapp/callback/)
    • The information passed by facebook in the callback is parsed by your application which then determines what gets returned and hence displayed in the canvas.
    • Think proxy (indirect connections).
    The full list of goals for the HelloPylons application are: Keep syntax as simple as possible (no decorators, etc), Keep all logic in the controller so its easy for a Pylons novice to see whats going on, print and decode everything that gets sent in the facebook callback to the console in plain english.

    The application comes bundled with the pyfacebook library and assumes that you have read chapter two and three of the excellent freely available pylons book and or are familiar with the basics of how Pylons works. I also assume that you have read the facebook developer getting started page.

    In order for this demo to work you will need to edit development.ini, change the port to something appropriate and add the api_key, app_id, url and secret key for your application. All of these should be provided when you create an application on facebook (follow the instructions on the facebook developer getting started page).

    September 30, 2009

    Slides from my talk on Facebook and Pylons

    I had a great time speaking about the challenges of developing Facebook applications in Python using Pylons at the PyWebSF meet up last night. The focus of my talk was on Facebook’s canvas/callback http request flow and how to handle it within your Pylons controller. I will be doing a follow up talk at the October PyGameSF meet up where I will demo a Facebook game I have been working on. The slides for the meetup can be found here. I will post a hello world Facebook/Pylons example in the near future.

    July 5, 2009

    Happy Meal

    Filed under: Education, Games, Interesting, Personal, Random, Technology — Tags: — admin @ 9:11 pm
    A never ending source of fascination for me is why people eat what they do. In particular I find it most strange that a glorified burger joint is the world’s largest chain of fast food restaurants, serving nearly 47 million customers daily from Dublin to Tokyo. Of the endless variations of food evolved over thousands of years from a myriad of different cultures around the globe why did this one franchise do so well? A large part of this success clearly lies in superior marketing, in particular targeting children and by association their parents.

    When considering the marketing phenomenon that is McDonald’s an interesting point to note can be found in a book written by Eric Clark called ‘The Real Toy Story’; In it the author claims that about 1/3 of all toys sold in America come from fast food restaurants and that McDonald’s has now become the world’s largest distributor of toys through its chain of 31,000 restaurants.

    At McDonald’s toys are distributed with happy meal’s. A happy meal seems to cost between $3 to $5, making just the food part of the meal yourself would probably cost roughly $.97. Even taking into account marketing, rent, wages and other overhead expenses, economies of scale makes it seem doubtful that McDonald’s is spending much more than this figure per meal on the edibles. According to an article in the new york times, food and toy executives estimate these toys cost somewhere between 30 to 50 cents each to make. When the costs are seen in this light, a 30 to 50 cent toy is a significant investment.

    In the same new york times article food industry consultants and former fast-food executives also claim that a popular toy can increase traffic in a fast-food restaurant by 4 percent and a very successful giveaway might drive up visits by 15 percent. Clearly happy meal’s are sold as a loss leader in order to draw kids and hence families in thus stimulating sales of other more profitable products.

    An interview dealing with the topic of marketing to kids taken from the documentary the corporation, with Lucy Hughes a VP at Initiative Media casts this strategy in an insidious light:
    “If we understand what motivates a parent to buy a product, that if we could develop a creative commercial, you know a 30 second commercial that encourages the child to whine or show some sort of importance in it that the child understands and is able to reiterate to the parents, then we’re successful.”
    In the west child hood obesity is more and more being seen as a public health concern brought about by a combination of poor diet, sedentary lifestyle and genetics. In an effort to tackle one aspect of this problem a number of countries are calling for a ban on the distribution of such toys with food. In Brazil recently a prosecutor charging that toys sold with meals in fast-food outlets can lead children to develop bad eating habits, asked a judge to ban such sales nationally at chains including McDonald’s and Burger King (link). In Australia a group called the obesity policy coalition is also calling for a similar ban (link).

    The above calls for legislative solutions beg a few important questions be asked. At what point does packaging end and product begin? Taken to its logical conclusion should all food deemed unhealthy be sold in soviet union style bland boxes with just the price embossed on the front. Also is distributing toys with junk food inherently bad? Setting irony aside for a moment, McDonald’s is the current sponsor of the World Cup, would distributing a football with a happy meal as part of a future promotion be a bad thing?

    The tone of the above articles also kind of imply that only very young children are susceptible to such nefarious campaigns. This is not the case. An article in harpers discussing the toy industry in China and specifically one company (Red Magic) that provides similar toy swag to restaurant and drinks companies offers this insightful tidbit:
    “Red Magic claims to have sold more than 20 million of these toys in twenty different countries,mostly to boys and men between the ages of fifteen and thirty-five, by deploying a marketing technique that McDonald’s pioneered thirty years ago, when, in an effort to boost declining sales, it introduced the Happy Meal, luring children and therefore their parents to restaurants with the promise of cheap toys. It could be argued that the Happy Meal, and similar gimmicks, saved the fast-food business. Red Magic uses the same marketing technique on teenagers and adults. And it works. For a while in Hong Kong, when you bought eight bottles of San Miguel beer, you got one of fifteen different limited-edition Red Magic collectible dolls, but you couldn’t choose which one. This “gambling element” kept customers “drinking and drinking and drinking and paying,” Wong explained. “When I go to see the customer—they buy and buy and buy, and they can’t get the one they want—I feel very happy inside.””

    So why do inedible things have such an effect on what we decide to eat? How does a little plastic figurine or a baseball card fit in with your self image? Does it matter if the actual toy is real or not? Would a digital gift, an extra level or character in some computer game, have just the same or better effect? Right now more ingenious ploys leveraging new technologies such as social networks are being devised and deployed on a daily basis. A good example of one such recent promotion was a facebook application that required you defriend 10 of your contacts in order to get a free whopper (link). I think this is only a crude beginning, in the future we will see social networks and other cost effective digital media being used to sell food.

    At the end of the day marketing is an arms race, banning toys at best will only slow the spread of bad eating habits down for a short period of time. Short of an outright ban on advertising unhealthy food I don’t see any legislative solution that’s workable. Of course this raises yet another question, who gets to decide what is or is not healthy and what should the criteria be?

    June 3, 2009

    Random Tech Nugget: How to find what hardware you are running on with OpenBSD

    Filed under: Linux, OpenBSD, Technology, linkedin — Tags: — admin @ 10:12 pm

    My website, PyGameSF, email and all of my miscellaneous projects are hosted by a computer cooperative called unworkable which was setup by David Cathcart, Niall O’Higgins, myself and some other friends a couple of years ago after college. The physical manifestation of this coop is a machine running OpenBSD that currently lives in a data center in Santa Clara.

    The coop is funded by annual membership fees, the more members we have the less the fee’s are. Only people we know and have an existing real world relationship with can become members. Membership means you get root access and an equal share of the system resources. Unworkable is run as a Doococracy, members generally help out where they can and offer technical advise and support to other members when needed. Anyway, enough back story.

    At the moment I am in the process of creating a blog for unworkable , one of the things I wanted to put up on the blog is an accurate description of what hardware we have. Rather than digging up old manuals to find model numbers I decided to take advantage of the excellent infrastructure provided by OpenBSD.

    If you want to find out what model mother board you are running on issue the following  sysctl command:

    sysctl hw.product

    This outputs:

    w.product=H8DAR-T

    A quick google for part number H8DAR-T reveals the following motherboard (Supermicro H8DAR-T-O) and a wealth of handy stats about our system.

    Ok so thats the motherboard taken care of now for the hard drives in the system, if you are using a raid controller type the following bioctl command substituting an appropriate value for arc0:

    sudo bioctl -h arc0

    This command prints out the following:

    Volume  Status               Size Device 
     arc0 0 Online               2.0T sd0     RAID5
          0 Online               699G 0:0.0   noencl
          1 Online               699G 0:1.0   noencl
          2 Online               699G 0:2.0   noencl
          3 Online               699G 0:3.0   noencl
     arc0 1 Online              47.5G sd1     RAID5
          0 Online               699G 0:0.0   noencl
          1 Online               699G 0:1.0   noencl
          2 Online               699G 0:2.0   noencl
          3 Online               699G 0:3.0   noencl

    Searching for one of the serial numbers ST3750640AS 3.AAE, provides the following result. The systems raid controller can be found quite easily by doing the following:

    grep arc0 /var/run/dmesg.boot

    Which spits out:

    arc0 at pci2 dev 14 function 0 “Areca ARC-1110″ rev

    Likewise the systems cpu can be determined in similar fashion:

    grep cpu* /var/run/dmesg.boot

    Which yields (most pertinent information highlighted in bold):

    cpu0 at mainbus0: apid 0 (boot processor)
    cpu0: Dual Core AMD Opteron(tm) Processor 275, 2205.29 MHz
    cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,NXE,MMXX,FFXSR,LONG,3DNOW2,3DNOW
    cpu0: 64KB 64b/line 2-way I-cache, 64KB 64b/line 2-way D-cache, 1MB 64b/line 16-way L2 cache

    cpu0: ITLB 32 4KB entries fully associative, 8 4MB entries fully associative
    cpu0: DTLB 32 4KB entries fully associative, 8 4MB entries fully associative
    cpu0: AMD erratum 89 present, BIOS upgrade may be required
    cpu0: apic clock running at 200MHz
    cpu1 at mainbus0: apid 1 (application processor)
    cpu1: Dual Core AMD Opteron(tm) Processor 275, 2205.00 MHz
    cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,SSE3,NXE,MMXX,FFXSR,LONG,3DNOW2,3DNOW
    cpu1: 64KB 64b/line 2-way I-cache, 64KB 64b/line 2-way D-cache, 1MB 64b/line 16-way L2 cache
    cpu1: ITLB 32 4KB entries fully associative, 8 4MB entries fully associative
    cpu1: DTLB 32 4KB entries fully associative, 8 4MB entries fully associative
    cpu1: AMD erratum 89 present, BIOS upgrade may be required


    June 1, 2009

    Random Tech Nugget: List all atributes of a python object

    Filed under: Education, Programming, Python, Technology — Tags: — admin @ 8:02 pm
    One of the nice things about an interpreted language like python is that you can fire up the interpreter, start hacking on an idea one step at a time and instantly check assumptions for each line of code. When ever I am unsure about a few lines of code in a feature I am adding to a project, I take a step to the side and do this. More often than not I will know what I want to do but not the specific function to call or variable to access.

    Rather than break the flow of my coding by typing help() and wading through documentation for a particular module, when dealing with a particular object , I prefer to use the dir function. The dir() function allows you to instantly see what attributes/methods are attached to your instance, for example:

     Python |  copy code |? 
    1
    >>> dir(Dog)
    2
    ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__getattribute__', '__hash__', '__init__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', '_iter_hypernym_lists', '_lemma_pointers', '_pointers', '_related', '_wordnet_corpus_reader', 'also_sees', 'attributes', 'causes', 'closure', 'common_hypernyms', 'definition', 'entailments', 'examples', 'frame_ids', 'hypernym_distances', 'hypernym_paths', 'hypernyms', 'hyponyms', 'instance_hypernyms', 'instance_hyponyms', 'jcn_similarity', 'lch_similarity', 'lemma_infos', 'lemma_names', 'lemmas', 'lexname', 'lin_similarity', 'lowest_common_hypernyms', 'max_depth', 'member_holonyms', 'member_meronyms', 'min_depth', 'name', 'offset', 'part_holonyms', 'part_meronyms', 'path_similarity', 'pos', 'res_similarity', 'root_hypernyms', 'shortest_path_distance', 'similar_tos', 'substance_holonyms', 'substance_meronyms', 'tree', 'verb_groups', 'wup_similarity']

    March 4, 2009

    Random Tech Nugget: Wordpress + svn update the only way to fly.

    Filed under: Technology, wordpress — Tags: — admin @ 1:19 pm
    Maintaining numerous websites can be a real pain: dealing with spam, security vulnerabilities, wierd browser issues,  blogging software that’s written in an inherintly flakey a language which makes up about 90% of the exploit traffic to bugtraq (php I am looking at you), the list goes on and on. The key is to where possible pick the right tools and refine your process where possible.  However as is oftern the case with life, sometimes you have to comprimise. Wordpress,  the software that powers this blog is one of those comprimises.  In my experience one of the best ways to install and update is to do so via SVN.

    Install:

    $ mkdir blog
    $ cd blog
    $ svn co http://svn.automattic.com/wordpress/tags/2.7.1 .


    Once you have done the above, simply point your browser at the setup script and follow the standard wordpress install instructions.

    Upgrade:

    1) make a backup

    $ cd blog
    $ svn sw http://svn.automattic.com/wordpress/tags/2.7.1/ .


    And your done. Tadhg O’higgins also has a great article on working with wordpress which is worth a read if you value making your web life that little bit easier to manage.

    Older Posts »

    Powered by WordPress