All Your Autorotate Are Belong To UINavigationController

so if you’re like me, you usually don’t fuck around with screen orientation. You make an app to auto rotate.

But if your building an app in a day for a pitch that scans barcodes and plays videos, and you don’t have full res images assets, basically screen shots. You have some pages that should auto rotate and some that shouldn’t. Here’s how you do that.

First off, you’ve embedded your project in a UINavigationController and you thought that was neat. Hurray. Second, you want to make sure in your app’s summary settings that you’ve set the interface orientation to everything.

Now you can start coding. First, make a subclass of UINavigationController and assign your nib navigation controller to be that class:

In you sublcass navigation controller now specify two function in your .m file:

- (BOOL) shouldAutorotate
{
    return [[self topViewController] shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

This allows all orientations and sets the “shouldAutorotate” to your view controllers function autorotate.

So now in every view controller, just set the function in your viewController.m file:

- (BOOL) shouldAutorotate
{
    return NO;
}

or yes if you feel like it.

So there you have it, specify, when you need to.

How to make a UIScrollView Programmatically

Ok, so I’ve stilll never made this work in interface builder. But it’s not that hard to make it in code.

You want to add a scroll view to the middle of your screen, in your view controller.m file:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    NSLog(@"viewDidLoad");
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 107.0, 320.0, 415.0)];
    contentImage = [UIImage imageNamed:@"video_wall.png"];
    contentImageView = [[UIImageView alloc] initWithImage:contentImage];
    contentView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 463.0)];

    [contentView addSubview:contentImageView];
    [scrollView addSubview:contentView];
    [scrollView setContentSize:CGSizeMake(320.0, 463.0)];

    [[self view] addSubview:scrollView];
}

Make sure you manage these variables however you do, for instance I have in my .h file:

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UIImageView *contentImageView;
@property (nonatomic, strong) UIImage *contentImage;

So there you have it.

Fastest Loops in Javascript

I’m always interesting in Javascript and which constructs perform better than others. There are alot of funky things about this language, but for loops always seem to be a moving target for me.

I tend to stick with the regular var i = 0 loop, because it’s easy to understand:

for(var i = 0, l = something.length; i < l, i++) {
   // do something
}

But there are options, like this one:

var a;
while((a = arr[i++]) !== undefined) {
  someFn(a);
}

Which also seems to be the fastest construct, according to this site: http://jsperf.com/fastest-array-loops-in-javascript/5

And the award for most inventive?


var arr2 = arr.slice(0);
while( (i = arr2.shift()) !== undefined ) {
  someFn(i);
}


My point is, there are alot of ways to skin a cat, it turns out, you can get significant performance boosts by googling to see if there’s not a better way to do things. Even if it’s something you’ve been doing for years and taking for granted.

Launch At Login Cocoa

recently I needed something that launched itself when a user logs in or restarts their computer.

Found this nifty little library: https://github.com/biocross/LaunchAtLoginController–with-ARC-

Basically, you load those two files into xcode, the do the following:

  1. Hook a button or segmented control up to an IBAction
  2. in the action load the launchController
  3. set the launch controller to launch at startup
  4. profit

In reality it looks like this:

Then in your IBAction do this:

NSSegmentedControl *segment = (NSSegmentedControl *) sender;
    NSInteger selectedSegment = [segment selectedSegment];

    LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init];
    BOOL launch = [launchController launchAtLogin];

    if (selectedSegment == 0) {
        [launchController setLaunchAtLogin:YES];
    } else {
        [launchController setLaunchAtLogin:NO];
    }

Finally, make sure you include “#import “LaunchAtLoginController.h” or whatever you named the class in your header file.

That should be it. Get an action from the user, set the launch to yes and away you go!

How the F*** to Encode URL in Objective-C for IOS

Google it.

You’ll find there are a ton of solutions, all of them produce memory related errors because of ARC.

if you want to do it in a way that works, just:

NSString *charactersToEscape = @"!*'();:@&=+$,/?%#[]" ";
    NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
    
    NSString *url = [NSString stringWithFormat:@"%@", @"http://stuff.com/things/"];
    NSString *encodedUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];

Jesus…this took me way too long to figure out

Doritos Bold Stage

How do you make 70,000 people at SXSW care about a chip brand? Produce three days of can’t-miss performances, all inside the world’s largest vending machine.

That’s exactly what we did. I was pulled in last minute to help make the control software that would allow users to go up on stage, select a bag and try to catch it as it falls from a giant vending machine.

My Role

Tech direction and production of the native IOS apps that interact with the giant vending machine. I also built a simple IOS app that allowed people to share photos of themselves catching the bags of Doritos. This app allowed them to share via Facebook, Twitter and email.

You can see a video of the app working here:

And a user flow for the share app.

Adobe Remix

Our team was asked to take part in the Adobe Remix project, a showcase of creative interpretations of the Adobe logo.

We wanted to highlight the creative activity that adobe products enable. So we re-created Adobe’s logo as a physical installation with 100 handmade cubes, each one correlating to an artist using Adobe software in real time.

Each cube captures a single pixel from an individual artist as they work on their creative projects. “Adobe Lights,” which lives at Adobe’s San Francisco headquarters, brings together physical, digital and interactive elements into one living logo installation.

The Team

The entire beta team participated in this project in one capacity or another. Thanks to Kia and Russell for building the site to display our work. Thanks to Stevie for the design work. Thanks to Chris and Pablo for your amazing ideas. To Marpi for his 3d digital version of the wall. Michael Phillips organized the project beautifully. Kalle fought for us to build it in-house. Finally to Patrick, for your tireless work (physically constructing the wall) and positive attitude throughout, thanks!

team

My Role

Concept and production.

Technologies

I built the following (Thanks to Patrick Wong for assembling the physical components of the wall!):

  • Physical – I designed the electronics to power and connect the wall to realtime data
    • LEDs – 3000 individually addressable WS2812 LEDs in strips of 60
    • 4 X 60 Amp 5V power supplies
    • 4 X Arduino Megas
    • 1 Mac Mini
  • Digital – I designed and built the infrastructure to manage the wall and the following pieces
    • Native app that artists can install (runs in the background and broadcasts color information over socket connection to server)
    • NodeJS Server (running on amazon Ec2) to receive artist color information, store and provide realtime updates to the wall
    • Native App (running on mac mini) to receive color updates over socket from the server, parse updates and send updates (byte level) to arduino megas over usb.
    • Custom Arduino mega software to receive updates from mac mini and control LEDs.

The Process

After we knew what we were going to make, I spec’d out exactly what we would need to build it. Because of the timeline, we had to get it right the first time. I wanted to make sure we could update every pixel on the wall (all 3000 leds) at 60 frames per second (I ended up only getting about 45). The power system was designed using fritzing.

wiring-diagram

Each cube in the wall had a strip of 30 leds wrapped around a tube sitting in the middle. Each 30 led strip connected to a different signal pin on the arduino mega. The wall itself was split into quadrants, so an individual arduino only controlled 25 cubes at a time. This also made communication over usb realistic.

the_setup

 

The final power board ended up looking something like this:

powerboard

These power boards sat directly behind the wall and fed the lights through individual cables. In theory we could disassemble the entire thing and make whatever new shape we want!

Here’s the wall without the acrylic panels:

blankwall

Testing the wall:

testingwall

A view from the back:

viewbackwall

And the final product (shot in the armory downtown):

finalwall

OMG OMG Tail?

So I have been trying to watch for a successful file upload in NodeJS for a while. Sure, you can use something inotify, but the process is heavy when all your looking to do is emit an event in NodeJS when a file is successfully uploaded to a directory on your server.

For starters, I have vsftpd running on an ubuntu installation. I upload to a directory and NodeJS watches for when the file is complete. Then adds it to a queue of files to process for later. I needed something light and fast. Kinda like tail..wait wuh???!

So here’s the deal you can set up a tail child process in node like this:

var spawn = require('child_process').spawn,
    tail = spawn('tail', ['-f', '/var/log/vsftpd.log']);

This will sit and monitor all the data coming through the tail. it’s a persistent child process so not too expensive either.

You can watch the output coming through like this:

tail.stdout.on('data', function(data) {
    console.log("stdout" + data);
});

tail.stderr.on('data', function(data) {
    console.log("stderr" + data)
});

tail.on('close', function(code) {
    console.log('closed: ' + code)
});

The amazing part is that vsftpd logs an even when the file is successfully uploaded, so no more polling for files and determining whether they are complete, or setting up watches on files that have been created but not finished yet. So efficient. Just parse the log file for a line like “UPLOAD” and get the file name and “WHABAM!!!” you’re done.

Can’t Connect Workbench to Amazon RDS

well shit…

This one took me about 45 minutes. Kept getting hanging errors while trying to connect mysql workbench to amazon’s RDS services. So here’s what I did. Not sure what fixed it.

I followed the tutorial here: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithSecurityGroups.html

And then added a rule (which is probably really dangerous): CIDR/IP: 0.0.0.0/0 to allo connections from all sources.

Woohoo! it works.

How to search Mint.com For Transactions During Tax Time

Ok, this isn’t really coding…

but still a great way to gather your deductions for tax time prep and shit.

First off, search by URL:

https://wwws.mint.com/transaction.event?query=category:"13"&startDate=01/01/2013&endDate=01/01/2014&exclHidden=T

This says, search category 13 (which I think is internet related stuff) from 1/1/2013 to 1/1/2014. It will give you the full report.

Then if you want to exclude certain items in the category, type in the search field:

-category:Utilities

To exclude something like utilities. If you want to add a category:

category:Entertainment

Same thing with Tags:

-tag:taxable

To remove items on the page with a tag of “taxable”. Etc.

Cool right?