How to Distribute Your Enterprise App IOS

Recently, my company got a fancy new ios enterprise account which allows you to distribute apps over the air to anyone in your organization. This is how you do it:

  1. When you are finished and ready to distribute you app, in xcode go to: Product –> Archive
  2. Your Organizer will appear with several options. Click “Distribute…”
  3. Select “Save for Enterprise or Ad Hoc Deployment”
  4. Select Your provisioning profile and click “Export”
  5. When you have the option to save the file, check the box that says “Save for Enterprise Distribution”
  6. Enter the url where the file will live. For instance “http://mysite.com/app/myapp.ipa”
  7. Organizer will export two files. a .ipa file (which is your app) and a .plist file (which is needed to install the app) Upload these to your server in the same spot you entered the above URL. These two files should live in the same directory.
  8. Now you need to upload your mobile provisioning file in the same directory. You can download your .mobileprovision file from the apple developer portal.
  9. Once that’s uploaded send an email to the person who is to install the app with the following format:
http://mysite.com/app/myapp.mobileprovision

itms-services:///?action=download-manifest&url=http%3A%2F%2Fmysite.com%2Fapp%2Fmyapp.plist

The user needs to download the mobileprovision file first. They will be asked to install it. Then they can click the other link to install the app on their phone.

Boom, done.

NOTE: if you update some devices and wish to refresh your ios team provisioning profile, you need to go into xcode to refresh it. The profiles won’t automatically refresh if you simply add devices on the developer portal. You need to also do this.

How to find your raspberry pi on a network

May have already written about this in one of my pi 101 posts. But here’s a simple command to find your pi if you accidentally boot it with no screen and you want to ssh in.

First make sure you have this: http://nmap.org/download.html

Then use this:

sudo nmap -sP 10.3.1.1-255 | grep raspberry

That should turn up the network IP address your pi on your subnet (NOTE: you may have to use 192.168.1.1-255) if you are working from a normal network.

My Global .gitignore

For all those who aren’t up with it, there’s a file you can put in your home directory called “.gitignore_global”. Read more about it here: https://help.github.com/articles/ignoring-files

Basically, it allows all your projects to ignore those pesky files you always ignore anyway, automatically. I thought it might be useful to post mine (ignores netbeans, logs, databases, mac files, android developer kit files, xcode files, eclipse files and compiled files):

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

# Netbeans #
############
nbproject

# android #
###########

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# IOS #
#######

*.swp
*.lock
*~.nib
DerivedData/
build/
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
!default.pbxuser
!default.mode1v3
!default.mode2v3
!default.perspectivev3
xcuserdata
*.moved-aside

# eclipse #
###########

*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

There you have it, I use netbeans, xcode, android and a mac. Just a helpful tip.

Beagle Bone SSH Password Not Working

For all those who updated angstrom then left their beagle bone alone for a year and are getting back into it…

If you’ve connected your bone via networked USB, just make sure you ssh like this:

ssh root@beaglebone.local

The password is empty so just hit enter. If you try to ssh by typing: ssh root@localhost you won’t be able to enter this password. You’ll error out, get frustrated and kick a puppy… don’t do that.

Debugging your websocket connections with curl

I recently needed a quick way to debug my socket connections. Of course, curl seems like the right tool for the job here so:

$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: http://www.websocket.org" http://echo.websocket.org

Change the urls to your server and you should see some upgrade information as your connection upgrades from http to ws.

Found this nifty little job here: http://www.thenerdary.net/post/24889968081/debugging-websockets-with-curl

Have fun!

Apache Benchmarking, Foreach with List and Other PHP 5.5 Stuff

Cool little tool for benchmarking which you have, if you have apache installed:

ab -n 100 -c 5 http://localhost/site.php

This says to test a page 100 times with a concurrency of 5. Apache will spit back some stats on it. Pretty cool.

Also, did anyone else know that you can use list in foreach loops now?

foreach ($array_of_stuff as list($other, $arr, $of, $stuff)) {
    echo $other;
    echo $arr;
    echo $of;
    echo $stuff;
}

Makes it super handy and way more readable than:

foreach ($array_of_stuff as $items) {
    echo $items[0];
    echo $items['things'];
    echo $items[2];
    echo $items[3];
}

And…

PHP finally added a “finally” block to their try -> catch block:

try {
    // do this
} catch(Exception $e) {
    // handle errors
} finally {
    // do this regardless afterward
}

Super easy.

NodeJS and Memcached: Installation

So you have a worker process that should update a web process so it can notify all your connected clients of something?

We there are a couple strategies for doing this.

  1. Shared memory between processes.
  2. Pub/Sub and messaging service
  3. TCP socket between processes.

#1 is not so scalable. It works really quickly on your machine, but as soon as you put your application into a situation where you need to communicate between two servers, you can’t share memory.

#2 is great, something like redis or mongoDB works fine for this. You can easily store a message in this queue and pull down the message as you need it.

#3 is what we will work on today. It involves installing something called “memcached” which is a fancy term for a TCP connection between two process. As messages are published on the socket, they are pulled in and read by the process on the other end.

First off, my local environment is a mac, my production environment is an ubunty EC2 instance. To get it installed on the mac, make sure you have xcode installed with the developer tools, then run the script below:

# memcached requires libevent
cd /usr/local/src
curl -L -O http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
tar -xvzf libevent-2.0.17-stable.tar.gz
cd libevent-2.0.17-stable*
./configure
make
sudo make install

# Compile memcached utility
cd /usr/local/src
curl -L -O http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
tar -xvzf memcached-1.4.13.tar.gz
cd memcached-1.4.13*
./configure
make
sudo make install

# Create .bash_profile alias to start memcached as needed
alias m="memcached -d -m 24 -p 11211" 

# Install autoconfig
cd /usr/local/src
curl -L -O http://gnu.mirrors.hoobly.com/gnu/autoconf/autoconf-2.69.tar.gz
tar xzf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/usr/local
make
sudo make install

# Compile and copy memcached.so module
cd /usr/local/src
curl -O http://pecl.php.net/get/memcache-2.2.7.tgz
tar -xvzf memcache-2.2.7.tgz
cd memcache-2.2.7
phpize
./configure --enable-memcache
make
sudo make install

# If using MAMP
# cp modules/memcache.so /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/
# emacs /Applications/MAMP/bin/php/php5.3.6/conf/php.ini # add line: extension=memcache.so

# If using Apache2
# sudo emacs /etc/php.ini # add line: extension=memcache.so

All the credit goes to this guy: https://gist.github.com/ryanjbonnell/3880048

Next you want to write a small script to test it. Set up two node processes and take this for example:

var Memcached = require('memcached');
var memcached = new Memcached('localhost:11211');
var lifetime = 86400; //24hrs
memcached.set('hello', 'world', lifetime, function( err, result ){
  if( err ) console.error( err );
  console.dir( result );
});
memcached.get('hello', function( err, result ){
  if( err ) console.error( err );
  console.dir( result );
});

All the credit goes to this guy: http://badsyntax.co/post/getting-started-with-the-nodejs-memcached-module

Finally, when you upload to the EC2 instance, you’ll need to install memcached there as well.

sudo apt-get install memcached
sudo vi /etc/memcached.conf
sudo /etc/init.d/memcached restart

And you should be good to go!

nTwitter won’t stream

This one took me a full 8-10 hours to figure out. I finally discovered a solution here: https://github.com/AvianFlu/ntwitter/issues/119

If you’re using ntwitter to stream twitter updates, and all of a sudden your stream stops, yet if you run:

var creds = twitter.verifyCredentials(function(err, response) {
    console.log('verifying creds')
    console.log(err)
    console.log(response)
});

Everything appears fine, your server time might be off. If your server time is off, you can’t authenticate properly with the streaming api because your oauth request carries a timestamp with it. Here’s what you do:

sudo ntpdate pool.ntp.org

Wow…

Crontab Revisited

I’m looking to get a cronjob set up on my new EC2 instance.

First off, I’m using Ubuntu 12.04. Secondly, it’s a default installation so I’m going to show you where all the default shit is.

Ok, so with any piece of tech your working with, the first thing you should do is figure out how to log output. On Ubuntu 12.04 everything for crontab gets logged to /var/log/syslog…so you’ll want to search that for cron entries when something doesn’t work:

less /var/log/syslog | grep CRON

Let’s get started the first thing we need to do is edit the crontab. There’s a brief explanation of the syntax here: http://www.adminschoice.com/crontab-quick-reference/

I’m starting out running my process every minute, then I’ll set the correct time settings when I’m sure everything is working. Start by doing this:

crontab -e

Now inside of crontab, initially I’m going to do something every minute. To do this, follow the syntax below:

* * * * * /usr/bin/curl -o /home/ubuntu/logs/temp.txt http://localhost/app/update/update.php

Now we can see an output happening at /home/ubuntu/logs/ where a file named temp.txt is being placed with the output of the file.

If you arent seeing this output try adding “>/dev/null 2>&1” to the end of the line so ubuntu doesn’t try to email the output of the cron to you. This might mess some stuff up. Your new command would be like this (notice I also changed the cron timing to be what I want, in this case, 3AM every day):

0 3 * * * /usr/bin/curl -o /home/ubuntu/logs/temp.txt http://localhost/linkedin/update/update.php >/dev/null 2>&1

That’s it, have fun!