Dev Diary

Install Tmux 1.8 on 12.04

sudo add-apt-repository ppa:pi-rho/dev (source)

sudo apt-get update (freshens the cache/database of packages)

sudo apt-cache show tmux (*optional, shows you available versions, 1.7 & 1.8 should be listed)

sudo apt-get install tmux

tmux -V

Block Objects in iOS

“Block objects can either be inline or coded as independent blocks of code. Let’s start with the latter type. Suppose you have a method in Objective-C that accepts two integer values of type NSInteger and returns the difference of the two values, by subtracting one from the other, as an NSInteger:”

- (NSInteger) subtract:(NSInteger)paramValue from:(NSInteger)paramFrom { 
return paramFrom - paramValue;
}

pure C function that provides the same functionality to get one step closer to learning the syntax of block objects:

NSInteger subtract(NSInteger paramValue, NSInteger paramFrom){
    return paramFrom - paramValue;
    }

You can see that the C function is quite different in syntax from its Objective-C counterpart. Now let’s have a look at how we could code the same function as a block object:

NSInteger (^subtract)(NSInteger, NSInteger) = ^(NSInteger paramValue,
    NSInteger paramFrom) {        
            return paramFrom - paramValue;
                };

Suppose we have a function in C that takes a parameter of type NSUInteger (an unsigned integer) and returns it as a string of type NSString. Here is how we implement this in C:

NSString* intToString (NSUInteger paramInteger){

    return [NSString stringWithFormat:@"%lu",
                (unsigned long)paramInteger];
                    }

The block object equivalent of this C function is:

NSString* (^intToString)(NSUInteger) = ^(NSUInteger paramInteger){

    NSString *result = [NSString stringWithFormat:@"%lu",
                            (unsigned long)paramInteger];

                                    return result;
};

The simplest form of an independent block object would be a block object that returns void and does not take in any parameters:

void (^simpleBlock)(void) = ^{
/* Implement the block object here */

};

Block objects can be invoked in the exact same way as C functions. If they have any parameters, you pass those as you would for a C function, and any return value can be retrieved exactly as you would retrieve a C function’s return value. Here is an example:”

NSString* (^intToString)(NSUInteger) = ^(NSUInteger paramInteger){

    NSString *result = [NSString stringWithFormat:@"%lu",
                            (unsigned long)paramInteger];

                                    return result;


};

- (void) callIntToString{

    NSString *string = intToString(10);
        NSLog(@"string = %@", string);

}

“The callIntToString Objective-C method is calling the intToString block object by passing the value 10 as the only parameter to this block object and placing the return value of this block object in the string local variable.

Dash for Offline API Reading

Dash is a great tool for reading documentation offline of your favorite framework or library. You can also generate your own docsets and host them as feeds so anyone can use it. I have found an open source iOS project on github (https://github.com/omz/DocSets-for-iOS) for reading the mac os x / iOS docsets which is a bit dated but have not been able to find any project that’s compatible with Dash docsets in general. Maybe a side project?

Parse and Facebook Integration for iOS and Ideas

Log in facebook in parse allows for read permissions. This doesn’t require to launch facebook app. Simple popup allows this. Instead does everything in the background. We can pull fb user’s id, name etc. with this. We can then link this to PFuser object in our User table. Parse allows devellopers to store and link uploaded photos by users on Parse. This opens up freedom to create applications to have linked users (by facebook) on Parse. One scenario:

            User A logs in with facebook on app X. App X grabs all of his fb
            friend list and save it to Parse. Then, his friend user B logs
            in with facebook using app X. This gives us possibility to send
            a notification to the user A saying, your friend just joined the
            app. 

Birthdays:

      Login with facebook, your friends birthday and get automatic
      notification to your phone.

Mavericks YouCompleteMe

If you start getting lots of errors on your YCM plugin for vim, it’s most likely using 10.9. What you need to do is to compile your vim on 10.9. If you are lazy, go grab macvim and just copy the mvim script that’s in the package to your /usr/local/bin dir. Delete the old vim binary and just create a symlink [ ln -s /usr/local/bin/mvim /usr/local/bin/vim] and you are good to go.

Making Vim More Useful

To make vim more useful and act like bit like emacs, it’s possible to install this plugin called tslime.vim. I have tried official slime but unfortunately that created a lot of problems with tmux. This is the only fork that worked on multiple windows multiple panes setup. Once installed (I use pathogen to install it but you can use whatever you want) you can use to teleport the code to the node that’s running in another pane. It’s quite useful.

Another useful plugin is YouCompleteMe and ultisnips. Unfortunately it’s not seamless but it definitely gets the job done. It allows you to choose the dropdown snippets and allow you to choose those using and then going forward/back using and in the placeholder variables. There’s an issue that’s stated on the github that promises to fix the problem but unfortunately it doesn’t work for vim that runs in the terminal. For it to work probably one needs macvim.

Tern for vim is another useful pluging for doing javascript in vim. For me beside the killer feature is to allow me to jump to defition of functions. Follow the installation instructions and then whenever cursor is on a variable or a property TernDef takes you there. I have just started using it so, at this point scratching the surface. Another handy vim command <c o > and <c i> allows to go jumpback to old cursor positions if one wants to go back.

These are all useful additions to vim workspace.

Installing Crouton on Samsung ChromeBook

I am considering getting a cheap laptop and turn that into a developer machine. I don’t like using MBP when I am in the bed being the main excuse. It looks like Crouton is the way to go for hacking the Chromebook into a debian machine. Only downside is Samsung ChromeBook is ARM based, which means it’s not possible to run binaries that are not compiled for ARMs.

http://www.howtogeek.com/162120/how-to-install-ubuntu-linux-on-your-chromebook-with-crouton/

https://news.ycombinator.com/item?id=6499625

http://pclosmag.com/html/Issues/201109/page08.html

Javascript Dependency Management

Unlike many other languages javascript doesn’t have a standard way to import modules. This made people to come up with different solutions like CommonJS, AMD or using plain old global namespace. It took me a while to understand what’s going on with the whole dependency management eco-system and what they mean and how they work.

Here are a few webpages to grasp it better:

http://yahooeng.tumblr.com/post/62383009835/javascript-modules-amd-and-the-road-ahead

http://blog.startifact.com/posts/overwhelmed-by-javascript-dependencies.html

http://blog.testdouble.com/posts/2013-06-16-unrequired-love.html

http://dontkry.com/posts/code/browserify-and-the-universal-module-definition.html

Generally there are two camps, RequireJS and CommonJS. CommonJS is similar to how npm but AMD people (RequireJS) think it’s a javascript hack and it doesn’t conform to the standards. From the other side, the critization is, RequireJS adds a lot of headache when project gets bigger.

It looks like with ECMAScript 6, Javascript folks are going to try to come up with a cleaner and more important standard way of handling all these tasks.