Git Tracking Remote Branches

For some reason, I’ve always failed to remember what the command to track a remote branch is in git. I look it up on this page everytime I want to do it:

Well no more. I figured if I write a post about it, I will remember it so here we go:

git fetch origin
git checkout -b somename origin/somename

That’s it… the branch will be set up to track the remote and you are switched over automatically.

Using the Facebook iOS SDK in Swift

Just a quick video to show you how to use the facebook native ios sdk in swift.

follow the directions to get your plist file updated here:

Once that’s done follow the instructions to add your build identity to facebooks records. Then…

  1. drag the frameworks into your project
  2. update your appdelegate file
  3. update your view controller
  4. make your view controller a delegate for the login button
  5. test

replace your applicationdidlaunchwithoptions:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

Then add the following:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)

Then in your “applicationDidBecomeActive“:


NOTE: make sure to import:

import FBSDKCoreKit
//  ViewController.swift
//  FacebookTutorial
//  Created by Mike Newell on 8/13/15.
//  Copyright (c) 2015 Mike Newell. All rights reserved.

import UIKit
import FBSDKCoreKit
import FBSDKLoginKit

class ViewController: UIViewController, FBSDKLoginButtonDelegate {

    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.
        if FBSDKAccessToken.currentAccessToken() != nil {
            // user already has access token
        } else {
            let loginButton = FBSDKLoginButton()
            loginButton.readPermissions = ["email"]
            loginButton.delegate = self

    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated.
    override func viewWillAppear(animated: Bool) {
    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        println("logged in")
    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
        println("logged out")
    func logUserData() {
        let graphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
        graphRequest.startWithCompletionHandler { (connection, result, error) -> Void in
            if error != nil {
            } else {


That’s it! here’s a video explaining more:

There’s also a great tutorial for anyone looking to do the older “bridging” method of importing the sdk:

MPMoviePlayerController Black Screen When Fading

Let’s say you want to animate a new view controller in and immediately start playing a video. You might things it’s as easy as taking a static image of the first frame of the video as the background and then crossfading the video overtop when it’s ready to play…right?


This was a 24 hour bug for me. I kept seeing this black screen before the video loads. I tried adjusting alphas, delays before playing the video, even changing the background color of the view of the video itself! Nothing worked.

Normally many of these solutions would seem right! It turns out you need to look far back in time to find the solution. In IOS 6, MPMoviePlayerController was given a new event to catch. For those of us using “MPMoviePlayerLoadStateDidChangeNotification” you’re doing it wrong… You see this load event is telling you when the video content is loaded and can play all the way through, however, it does NOT tell you when your movie is ready for the display to handle it.

There’s a new-ish notification to watch out for, it’s called: “MPMoviePlayerReadyForDisplayDidChangeNotification” and it’s your silver bullet. This thing only fires after the video has loaded…and is ready for the display!

Set everything up like you normally would, ad your observer:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieReadyForDisplayChanged:) name:MPMoviePlayerReadyForDisplayDidChangeNotification object:nil];

Then add your handler:

- (void) movieReadyForDisplayChanged: (NSNotification *) sentNotification
    if (player.loadState & (MPMovieLoadStatePlaythroughOK)) {
        [UIView animateWithDuration:0.1 delay:0.1 options:UIViewAnimationOptionCurveLinear animations:^{
            // animation
            [[player view] setAlpha:1.0];
        } completion:^(BOOL finished) {
            // done
            [player play];

Now your video should only fade in when it’s ready for display. After fading, you actually call “play” on the controller.

I’ll make a video and post it later…


Local Website in an IOS App

So you’re a master at html5 and you want to build a native app on ios, but you don’t know swift or objective-c.

No worries, there are a ton of platforms out there to help with this. But with some basic knowledge of ios you can build an using mostly web technologies!

What we will do is a build a locally hosted website, put it inside a native ios app and run it all together to give the appearance of a native app but built using html5.

You can download the project on my github:


Timelapse Movie of Your Desktop While You’re Working

i want to start doing timelapses of coding while I’m working, so here goes:

First off set up a terminal command to take a screenshot every 25 seconds:

i=1;while [ 1 ];do screencapture -t jpg -x ~/Desktop/TrickyWays/$i.jpg; let i++;sleep 25; done

Next stitch together the screens with ffmpeg:

ffmpeg -framerate 1 -pattern_type glob -i '~/Desktop/screens/*.jpg' -c:v libx264 out.mp4

thats all!

Inline Video on the iPhone

This is an example of inline video playing on the iphone

Use cases include webGL video textures, interactive video experiences, and video timing projects.

Please contribute to the project:

An example:

 * Inline Video Player v0.0.1
 * Includes jQuery js
 * Copyright 2015 Mike Newell
 * Released under the MIT license
 * Date: 2015-18-07
 * TODO: look for the webkit-playsinline playsinline attributes and replace videos on iphones with canvas

var video = $('video')[0];
var canvas = $('canvas')[0];
var ctx = canvas.getContext('2d');
var lastTime =;
var animationFrame;
var framesPerSecond = 25;
function loop() {
    var time =;
    var elapsed = (time - lastTime) / 1000;

    // render
    if(elapsed >= ((1000/framesPerSecond)/1000)) {
        video.currentTime = video.currentTime + elapsed;
        ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
        lastTime = time;

    // if we are at the end of the video stop
    var currentTime = (Math.round(parseFloat(video.currentTime)*10000)/10000);
    var duration = (Math.round(parseFloat(video.duration)*10000)/10000);
    if(currentTime >= duration) {
        console.log('currentTime: ' + currentTime + ' duration: ' + video.duration);

    animationFrame = requestAnimationFrame(loop);

$('button').on('click', function() {

See the Pen InlineVideo by Mike Newell (@newshorts) on CodePen.