SVN 101

Let’s start with the basics. I’m assuming you know what svn is and the purpose for it. If not, use Google. This tutorial is to get you going with it. I’m assuming you have it installed and are working on a mac.


There’s an easier way to structure your project (sorry, I’m learning as I go here…)

Pretty simple, you’re going to create a place to put your repos, populate them, then checkout a working copy:


For those of you who want a simpler step by step version, see below:

Set up your test environment:
mkdir ~/Learning
cd ~/Learning
mkdir rawfiles
touch rawfiles/stuff.txt

First step is to create a local repository (I’m assuming we don’t want to make this first tutorial more complex than it needs to be…usually your repo lives on a remote server where people can get access, but we are going to work with everything locally to keep it easy):

Create a repo:
svnadmin create remote
Import your files:
svn import rawfiles file:///Users/{YOUR_NAME}/Learning/remote/trunk -m "initial import"

Now we assume the “remote” is our repo living on a server somewhere. Time to pull down the project so we can start working with it:

Checkout a working copy:
mkdir local
svn co file:///Users/{NAME}/Learning/remote/trunk local/trunk
Let’s see what we have in there:
ls -la local/trunk

“Trunk” is just the main repository. It’s common in svn to use trunk the same way someone might use “Master” in git. It’s the production version of things. Not required, but it is convention.

At this point you’re ready to begin working with the files. In 102, I’ll show you how to setup your project to ignore certain files and begin modifications and commits. Then we’ll create some branches and start merging!


Cordova Getting Started

Once you have it installed. Run the following:

cordova create hello com.example.hello HelloWorld
cordova platform add ios
cordova build

Open your project in Xcode (under the platforms folder/ios) and you should be able to run it on an ios device!


How To Build GearVR Apps with Unity


Great step by step instructions for setting up your environment correctly here:

Oculus Signature File:

Get your device id by:

adb devices

Copy the id and paste it on the site below to get your signature file

Oculus signature file:

Oculus Android Utility Package:

Download the oculus utilities package:

Made a quick video to show you how to build and run on GearVR:


Arguments has a length, Object Literals do not?

I’m going to research on this and get back here. Basically, I’m wondering the following:

Why am I able to test inside of a function for arguments.length. But I can create an object literal and length is undefined? example:

function count(a,b) {
    console.log(arguments.length); // 2

var obj = { a: 1, b : 2 };
console.log(obj.length); // undefined!



Guaranteed Instantiation in Javascript

quick one today.

Let’s say you like the constructor pattern for objects. You probably do something similar to this:

function Person(name) {
    var __ = this; = name;
    return __;

Let’s say you forget to use the”new” operator to instantiate the function and instead just call it as is while trying to assign it to a variable:

var mike = Person('Mike');
name = 'john';

console.log( // results in john

The problem is “this”. Without referring to the “new” keyword, the function’s “this” refers to the global “this”. When you call the function, it can collide with any other variable in the global scope.

Of course you can fix it by doing:

var mike = new Person('Mike');
name = 'john';

console.log( // results in mike

Of course, this is the right way to do it. But how can you make sure that even if the user doesn’t call it correctly, your class doesn’t create crazy collisions and potentially cause someone to spend hours debugging?

Easy! Check your object scope. Figure out who you belong to and force instantiation otherwise:

function Person(name) {
    var __ = this;
    if(!(__ instanceof Person)) {
        return new Person(name);
    } = name;
    return __;

Now your object will return an instance of itself, even if called the wrong way.

var mike = Person('Mike');
name = 'john';

console.log( // still results in Mike



Debugging Cordova Apps, My Way

Cordova is hard to debug. There are millions things that can go wrong and it hard to separate the easy to debug stuff from the rest once you start working with native. That’s why its important to make the parts that don’t depend on native functionality work in the browser first. Get it working, then when it’s finished, bring it into the native app and work from there. Here’s a quick video showing you what I mean:

If you’re interested in my grunt file here it is:

module.exports = function(grunt){

        pkg: grunt.file.readJSON('package.json'),
        		command:"cordova build",
        copy: {
                main: {
                        expand: true,
                        cwd: 'www/',
                        src: ['*', '**/*'],
                        dest: 'browser/'
                cordovasrc: {
                        expand: true,
                        cwd: 'cordova-browser-src/',
                        src: ['*', '**/*'],
                        dest: 'browser/'
        	files:['www/**/*.*', 'cordova-browser-src/**/*.*'],
        	tasks:['exec:prepare', 'copy']
        // watch the www folder and build cordorva
        // copy www to browser and load in cordova.js to test in browser

    grunt.registerTask('default', ['watch']);


And here’s the cordova.js file:

var cordova = { 
    init: function() {
        var event = new Event('deviceready');
    plugins: {
        notification: {
            local: {
                on: function(listener, callback, context) {
                    document.addEventListener(listener, callback, context);
                getAll: function(callback) {
                    var notifications = [];
                hasPermission: function(callback) {
                schedule: function() {
                cancel: function(id, callback) {
                    var notification = {
                        stuff: 'things',
                        id: id
                registerPermission: function(callback) {
    InAppBrowser: {
        open: function(url) {
            window.location = url;

var StatusBar = {
    hide: function() {
        return true;

setTimeout(function() {
}, 1000);

It will fire a “deviceready” event to kick the whole thing off!



Uploading multiple APKs to the Play Store from Cordova and Crosswalk

Let’s say you have a low version release and a current release for your app. Let’s also say you’re using crosswalk or another plugin that builds for different device architectures. We can still do it!

It all depends the android version code. If you take a look in your android manifest you’ll see something like:


Basically it’s a version code that (among other things) tells google play that this is a new APK. You need to increment this every time you upload a new APK, even if its meant to support the same version!

Here’s the code:

# in your config xml file
# add the following attribute to "widget"
# should look something like: <widget id="com.gsp.appName" version="1.2.5" android-versionCode="102052"

# in your project root
cordova build --release android

# cd into your apk folder
cd platforms/android/build/outputs/apk

# if you havent already, generate a keystore file and save it someplace safe
# this file will allow you to make updates and sign your app, without it 
# you're screwed, so make sure you keep it. You can sign other apps with it.

# sign your apk with your keystore file
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/PATH/TO/FILE/your_key.keystore android-release-unsigned.apk alias_name

# now verify with zipalign
~/Library/Android/sdk/build-tools/23.0.0/zipalign -v 4 android-release-unsigned.apk YOUR_APP_NAME.apk

#once verified, upload it to the play store apks.

# increment the version code for your next apk
# should look like: <widget id="com.gsp.appName" version="1.2.5" android-versionCode="102053"

# repeat the building through uploading steps, repeat as necessary

Here's a video to show you how to do it:


Publishing Your Cordova App to the Play Store

You’re done! Now you want to publish? There’s a great resource here:

But I’ll repost the instructions here, in case the page goes away.

First you need to build for release:

cordova build --release android

If you have a keystore file already you can skip the next part. Basically, google requires you to sign the app, they will use this public key to verify you on your updates, so make sure you keep the .keystore file around:

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

Next you need to sign it with the keystore file:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name

Now to the only trick part of this…

You need to “zipalign” your file:

zipalign -v 4 HelloWorld-release-unsigned.apk HelloWorld.apk

Just make sure you have access to the zipalign executable from your terminal, if you don’t you could do something like this:

~/Library/Android/sdk/build-tools/23.0.0/zipalign -v 4 HelloWorld-release-unsigned.apk HelloWorld.apk

If you’re on a Mac that should work. Now go to the play store console:

You need to pay $25 to get into their developer program, once you’ve done it, you should be able to create a new app and upload your apk that you generated above.