Please watch this video then DO something.

March 08, 2012 Comments: 0

Lately I've been working steadily towards getting an iOS app released for my company, KaiNexus.  The first pass at this app will have the basic ability to submit an an idea from your phone and be able to attach a picture.  Since I am still a novice with Objective-C it was no surprise when I ran into a brick wall when trying to upload the image from the app.  This prompted me to ask on stackoverflow to see what I had done wrong.

As it turns out, I was using an incorrect combination of line endings and content types.  I now have working code in my app and figured I would share it so that anyone else running into this problem would have a starting point.  Below is the function I wrote to handle uploading an image in Objective-C on iOS 5 (the grails peices can be found on the SO question).

+ (BOOL)uploadImage:(UIImage *)image withName:(NSString *)fileName toURL:(NSURL *)url {
    NSData *imageData = UIImageJPEGRepresentation(image, 100);
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];

    NSString *boundary = @"0x0hHai1CanHazB0undar135";
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
    [request setValue:contentType forHTTPHeaderField:@"Content-Type"];

    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding: NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"imageToAttach\"; filename=\"%@\"\r\n",fileName]dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:imageData];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:body];

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

    NSLog(@"%@",returnString);

    return YES;
}
February 23, 2012 Comments: 0  ::  Tags: image , ios 5 , upload

I am currently working through an older Cocoa book and learning how to develop apps for the Mac.  While building the sample that demonstrates saving and opening files I noticed that my little application was already taking advantage of Lion's new autosave and versions support.  I recorded a quick video showing how easy it was to add this support.

November 13, 2011 Comments: 0  ::  Tags: autosave , lion , os x

With all the Adobe layoff news going around it makes me nervous about future support of ANY of their development products. Enough so that I am recommending that my friends and colleagues bone up on other technologies. Learn Grails, Closure, Python, Rails, whatever. Get your hands dirty with HTML5, JavaScript, and CSS3. Still want to run CFML applications? Not to worry, there are 2 VERY good solutions for that. Check out Railo or OpenBD, they are both free, open source and, in my not-so-uncommon opinion, better than Adobe's ColdFusion. Still need to do Flex development? Well, for now the Flex SDK is open source and free. And with tools like FDT going to a freemium model you can get setup with a low cost development environment and hardly miss a beat.

I know that change is hard, but it can be done. Equip yourselves with knowledge, don't put yourselves in a position that makes you an "antique". Read up on the new hot stuff. Even if you don't end up using that tech you'll be a better developer for just exploring the idea.

I'm not saying that everyone using Flash/Flex and ColdFusion are going to find themselves out of work tomorrow or even in 5 years. However, I am saying that you are doing yourselves a major disservice by not getting out of your comfort zones. I'll say it again. Go learn something new. Don't wait. Go home tonight and search YouTube for "Intro to {insert some language here}". Lastly, if you feel comfortable with it, share your experiences with the rest of us, get us motivated and excited about what's out there. It's okay to be open and public about learning a new set of skills, I guarantee you're not alone.

November 10, 2011 Comments: 18  ::  Tags: adobe , cfml , closure , coldfusion , css3 , fdt , flex , grails , html5 , javascript , learn , openbd , python , railo , rails

A while back I made some improvements to the backup scheme we use at KaiNexus. The requirements were pretty simple and straight forward. All our backups had to be encrypted, offsite and distributed. While there are a number of for-pay backup solutions out there we were looking for the bare minimum and free solution.

At the office, we all use Dropbox for file sharing so it seemed like a logical tool to use since we were all familiar with it. Dropbox lets us check off two requirements by being both off site and distributed. Here's my step-by-step guide on getting Dropbox setup on an Ubuntu server with minimal effort. I'm not covering the file encryption bit in this post but if you want to know how I did it let me know and I'll do a writup on it.

The steps outlined here were put together after reading through a couple of other guides. Feel free to read those guides if you want but you should be able to get everything you need from what I have below.

Install Python

  1. Install build-essentials and gcc

    sudo apt-get install build-essential gcc
    
  2. Download Python 2.5.5 (This seems to be the officially supported version)

    wget http://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz
    
  3. Extract

    tar -xvzf Python-2.5.5.tgz
    
  4. Compile and install

    cd Python-2.5.5
    ./configure --prefix=/usr/local/python2.5
    make
    sudo make install
    sudo ln -s /usr/local/python2.5/bin/python /usr/bin/python2.5
    

Install Dropbox

  1. Switch to root user

    sudo -s
    
  2. Create dropbox user and group and set the user's home to be /etc/dropbox

    groupadd dropbox
    useradd -r -d /etc/dropbox -g dropbox -s /bin/false dropbox
    
  3. Download the 64-bit Dropbox binary

    wget -O /tmp/dropbox.tar.gz http://www.dropbox.com/download/?plat=lnx.x86_64
    
  4. Create the dropbox user's home and set the ownership and permissions

    mkdir -p /usr/local/dropbox /etc/dropbox
    chown dropbox.dropbox /etc/dropbox
    chmod 700 /etc/dropbox
    
  5. Extract the dropbox binaries

    tar xvzf /tmp/dropbox.tar.gz -C /usr/local/dropbox --strip 1
    
  6. Remove the dropbox archive

    rm /tmp/dropbox.tar.gz
    
  7. Switch to the dropbox user

    su -l dropbox -s /bin/bash
    
  8. Set the user's permissions

    umask 0027
    
  9. Execute the dropbox daemon

    • Note: A URL will be repeated in the terminal window if the install machine is not registered to an account. Navigate to the URL (while logged in under the account you wish to link) and wait for the prompt to notify you that you are now linked. You'll get a simple welcome message.
    /usr/local/dropbox/dropboxd
    
  10. Terminate the dropbox daemon with ctrl+c

  11. Log out of the dropbox user

    exit
    
  12. Create the control script

    cat >> EOF | sed -e "s,%,$,g" >/etc/init.d/dropbox
    ### BEGIN INIT INFO
    # Provides:          dropbox
    # Required-Start:    $local_fs
    # Required-Stop:     $local_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the dropbox service
    # Description:       starts dropbox using start-stop-daemon
    ### END INIT INFO
    
    DROPBOX_USERS="dropbox"
    DAEMON=/usr/local/dropbox/dropbox
    unset DISPLAY
    
    start() {
        echo "Starting dropbox..."
        for dbuser in %DROPBOX_USERS; do
            HOMEDIR=%(getent passwd %dbuser | cut -d: -f6)
            if [ -x %DAEMON ]; then
                HOME="%HOMEDIR" start-stop-daemon -b -o -c %dbuser -S -u %dbuser -x %DAEMON
            fi
        done
    }
    
    stop() {
        echo "Stopping dropbox..."
        for dbuser in %DROPBOX_USERS; do
            HOMEDIR=%(getent passwd %dbuser | cut -d: -f6)
            if [ -x %DAEMON ]; then
                start-stop-daemon -o -c %dbuser -K -u %dbuser -x %DAEMON
            fi
        done
    }
    
    status() {
        for dbuser in %DROPBOX_USERS; do
            dbpid=%(pgrep -u %dbuser dropbox)
            if [ -z %dbpid ] ; then
                echo "dropboxd for USER %dbuser: not running."
            else
                echo "dropboxd for USER %dbuser: running (pid %dbpid)"
            fi
        done
    }
    
    
    case "%1" in
      start)
        start
        sleep 1
        status
        ;;
    
      stop)
        stop
        sleep 1
        status
        ;;
    
      restart|reload|force-reload)
        stop
        start
        sleep 1
        status
        ;;
    
      status)
        status
        ;;
    
      *)
        echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}"
        exit 1
    
    esac
    
    exit 0
    EOF
    
  13. Allow the control script to me executed and set it to autostart

    chmod a+x /etc/init.d/dropbox
    update-rc.d dropbox defaults
    
  14. Start dropbox

    /etc/init.d/dropbox start
    

You should now have Dropbox running as a service on your server. All that's left is to create your cron jobs that run your backup scripts and have those backup files placed into the /etc/dropbox/Dropbox folder.

October 22, 2011 Comments: 0  ::  Tags: backup , dropbox , linux , ubuntu