Monday, April 30, 2012

Blogging better than local files for data management

So I'm trying to find my notes on this years courses, and having opened lots of other text files recently, my class notes have been pushed off the TextEdit 10 item history, and I can't find it in the usual folders I would expect. Spotlight search always go off and does a complete full text search in the wrong location, AND my whole computer's slowed down because I am trying to push all the 6Gb screen flow files off to my external hard drive, and actually what I am trying to do is go through my 60 chrome tabs and off load the stuff that I don't want to lose when I next have to reboot it to run Google Hangouts, so it seems ironically that blogging is easier for this kind of data management than files on my hard disk.  If only my file manager let me type in file names and I got autocomplete like I do in my browser.

Anyway here is a good resource I found on learning github:

I also keep meaning to try out this approach of having git push to multiple repositories, so that a heroku push would also push to github:

I'm trying to pull all my github related resources together as I'm going to make github use a required part of all my future online CS classes.  I have gotten a bit sick of email attachments and dropbox.

And a random note, I managed to fix my printer by using a damp cloth:

Monday, April 23, 2012

iOS Storyboards tying me in knots

So I was wondering whether would it make sense to have a reciprocal segue when navigating down a hierarchy of categories of unknown depth in ios5?  I was thinking that the iOS navigation controller should provide the back button stuff etc., but it seems like if I was setting this up in a storyboard then I need to keep on seguing over and over again to the same controller displaying the current list of categories ...

After some help from iphonedev on I wasn't able to create a segue from one viewcontroller to itself, but I was able to make a seque to a clone of that view controller (Option Key drag to copy out of the left hand list view of items, thanks Psy) and I got the convoluted hook up pictured here.  Seems remarkably unDRY, but it works and I can now navigate up and down the category hierarchy with the navigation controller handling the back button to get back up again as necessary.

Friday, April 13, 2012

Eclipse Android Development Toolkit (ADT)

So I'm grading like 30 android phone and tablet projects for my mobile programming class, and there are things I keep encountering through the Eclipse Android Development Toolkit (ADT). Some good, some bad.

In particular there's this issue of the various android emulators and devices getting detached from the ADT, which means you can't deploy.  You then have to do this convoluted thing of going to the DDMS perspective in Eclipse, and clicking on the extra commands arrow in the device window, and then selecting "reset adb" and then gettting this confusing error message "Adb failed to restart! Make sure the plugin in properly configured", which you can't copy and paste and you have to ignore and then your devices/emulators connect back up.

This happens pretty regularly for me on OSX, and has been happening since at least Android 1.5 I think.  There are a few google hits on this, but not much, and this is likely in part that the error message can't be copied and pasted, and most experienced coders simply click "OK" and move on, but it's very confusing for newbies.

You'd have thought that a big company like Google could get this fixed up.  Maybe no one cares enough - maybe it's only happening for a few of us.  Maybe I'd have to bring it up at Google I/O or something to get it fixed.

In general though any other kind of error that can be copied and pasted is usually easily solved via StackOverflow, e.g.  when the ADT tells me that I can't install an app due to an existing one with the same signature and I have to type "adb uninstall whatever" in a shell and then I get this from the shell:

unknownc8bcc8da38b2:platform-tools samueljoseph$ ./adb uninstall edu.hpu.csci4702
- waiting for device -
error: more than one device and emulator

So I google the error message in quotes and I go to the stackoverflow hit since that's usually the best way to make progress:

and I see how to uninstall from a particular device.  So that all kinds of work, but I wonder why these IDEs couldn't be a little more user-friendly - I have similar issues with XCode.  With both XCode and Eclipse ADT I feel like a lot of disparate tools have been bundled together and are not quite working properly.  Maybe that's just the nature of things ...

Monday, April 2, 2012

Customizing Google Sites to Individual Users

Ever since Google Groups discontinued support for pages and files I've been running my classes on Google Sites, at least for hosting content.

The sign in link for individual users in Google sites is very carefully hidden at the bottom of the screen making it seem like the emphasis is on content hosting for all rather than on customizing content for individual users, but that is exactly what I'd like to do in order to, for example, show students in my classes which assignments they've completed etc.

It seems like there should be some way to do this, but my searches so far have proved inconclusive, as I keep searching and not quite coming up with anything concrete.  It seems like Google App Scripts should help, but I'll have to look again once the semester has finished:

XCode StoryBoarding and SplitViews

So I burnt a lot of time last week trying to get XCode Storyboards working nicely with UISPlitViews on the iPad.  One of the more helpful resources was this one:

which I found by searching Google for "programmatically trigger segue".  My previous search for "splitviewcontroller segue" was less helpful, turning up short, not really relevant StackOverflow posts.

I also skimmed the following tutorial, but wasn't able to pull the information I wanted fast enough:

Ultimately I got it all working, and I think the biggest roadblock was the idea that the segues still needed to be created in the StoryBoard interface, but that I would trigger them and catch them programmatically.  Given that I wanted different segues to take place depending on whether the user clicked a table cell in the master view, or the associated detail disclosure button.  The trick was to have segues in the Storyboard running from the master view to two other UI views, one for each of the possible segues, but then adjusting the segue type to specify the detail view to ensure that the right part of the splitviewcontroller was updated.

Particularly after some not too disimilar trials and tribulations with Android fragments it makes me wonder if there isn't some way to make mobile development a little less hazardous ...

Of course having got that working there was still the unpleasantly convoluted issue of trying to make the test in a UITableViewCell wordwrap to keep me entertained:

I kind of hacked a solution there.  It seems remarkable that there isn't a dynamic sizing solution that doesn't require hacking at code - maybe I just haven't found it yet.

I think I was also also tripped up by the detailTextLabel not being visible:

All my attempts to set a nice background gradient for some elements in the table view failed :-( The top three StackOverflow hits for my google search on "CAGradientLayer UILabel" seemed promising, but I couldn't get it to work.  I did however manage to get something to appear by creating a dummy transparent PNG of the right size and then was able to dynamically create a UILabel with a number on it.

Android ListViews in Tablet Fragments

Putting together a ListView demo for my mobile programming class turned out to be a bit of a pain. I guess I set myself for difficulty by trying to replicate Paul Hegarty's demo of adding a favourites list to a graphing tablet calculator, but I thought I had sufficiently reduced the difficulty level by not trying to replicate the iPad popover, and instead went for a simple ListView embedded in the main Calculator view.

I fell foul of a number of issues, several of which I have encountered before and one might have hoped I wouldn't have been tripped by them again.  They include

1) need for embedded ListViews to have special IDs
2) nature of ArrayAdapters
3) variations arising from fragments

One of the early errors that slowed me down and forced me to create a separate FavesFragment to handle the list in isolation was the "inflating fragment error"  The following StackOverflow posts helped orient me ...

I spent a lot of time thinking that an AsyncTask was going to be necessary in order to enable the listview data to be updated (e.g. add more rows), but that turned out not to be the case.  The key trick there was to do any addition to the data through ArrayAdapter.add, and basically forget about any reference to the initial data passed to ArrayAdapter - ultimately I just initialized with an empty ArrayList.  There were several confusing StackOverflow posts that deflected me from ultimately finding salvation in the android irc channel on

Well this second one should have helped me more, but I was trying to do much at once, as well as programming Pythonically in Java, which often gets me into trouble ...

And I think this android developer blog got me a bit further:

but annoyingly it was like much of the android docs; code fragments, but not an actual working system.  Ultimately it was IRC that sorted me out, with other developers pointing out that the key issue was updating the data through the ArrayAdapter itself.

I also burnt time seeing if I could get some simple persistence going with Preferences, but it seemed that unlike in iOS, I couldn't store any more than a simple set of Strings in light weight preferences, which wasn't quite sufficient for the stack object I was working with, or maybe it would have been okay?  Hmm ....

Language Models and Python Reflexes

So I burnt slightly more time than necessary on the NLP homework writing my own bigram/unigram calculating code in order to calculate plus one smoothing values on a small corpus.   However it was interesting Python background in terms of the much tripped over integer division issue in Python:

As well as an interesting review of the multitude of quick ways to get an item count from a list in Python:

and my old favorite how to grab a list pairwise in Python:

iPhone/iPad demos for online class

So I was impressed to see Paul Hegarty demo-ing iPad apps in the Stanford iOS class using an iOS dock to hdmi cable adapter, and there seem to be many of these available.  However it doesn't quite meet my needs for an online class.  I'd like to see my iPad or iPhone screen appearing in a window on my desktop computer so that I can run a demo and use Screenflow to record the activity on the phone/pad along with slides, XCode etc.

There seems to be some talk of supporting this via VNC or similar, but a superficial look suggests that all these are for viewing your desktop computer on your iPad etc., and not quite what I am looking for.