Selling photos on Picfair

As a keen photographer, I take lots of photos. It's not uncommon for me to shoot upwards of 500-600 photos in a weeks' holiday, and sometimes I like to feel that I've come home with some pretty good shots. I've tried my hand at submitting shots to the bigger stock libraries, but the process always seemed very complex, and the returns were never in your favour and also preferred top quality silly expensive hardware produced images. Canon 5D Quality, thousands of pixels by thousands of pixels, and shot with expensive prime lenses. Not that these requirements are unrealistic, they do charge top rate for their images, and they're all very high quality, but this meant my "hobbyist" shots were out of the running.

Then along came a UK startup Picfair.

The Great Bulgarian Adventure

It's been a year since we lived our Great Bulgarian adventure, 6 months spent living and working in the capital Sofia.

We arrived in mid february to a cold city, and a very unfriendly looking front door to our apartment building, our minds starting to wonder if this was such good idea after all. However, within a couple of hours, and short walk into the city centre for our first meal, our worries had been removed. We would get used to the broken paving tiles and the graffiti. Now we're back in the UK, we miss it, the friendly nature of the local Bulgarians, the great food and the months of blue skies.

Most of time in Bulgaria was spent surrounded by the historical buildings in the centre of the Sofia.

Capturing and processing photos on the iPhone

They say the best camera, is the camera you have with you, and for most of us, that will also be your phone. With an 8 megapixel sensor, the iPhone5 is already a pretty capable camera, then consider that modern smartphones are pretty powerful computers that allow you to do most

A recent snowboarding trip to Austria was a great opportunity to test out if just an iPhone was enough to capture some great images.

All of these photos were taken with an iPhone5 and processed on the phone with camera+. View the whole set on flickr

Building Astro Runner part 1

Like most software engineers, I've always got a few part-time side projects that work on, most start from what at the time seed like great ideas, most are started with great enthusiasm, most never see the light of day.

This is the story of side project that shipped.

It all started much the same as usual, have and idea, spend an evening playing around with it. Only this time I got a lot further than usual. I've been using X-Code, Objective-C and the iPhone frameworks with the iPhone simulator for other projects, so the tools are famililiar to me. My fulltime job at Kyan is mainly spent programming in Ruby, so the jump to Objective-C is quite straight forward.

My plan was to build a faux-3D endless runner game. I'd recently stumbled across a reference to how to use the UIKit framework to transform simple UIViews into 3D space. From there, I'd figure I could use some very simple animation and some collision detection, and I'd have the basis for the game. It couldn't really be that easy could it?

3 hours later

The Apple iOS frameworks are excellent. There really is no other way to say it. Within a very short space in time, I had the basic 3D environment built, animating 'obstacles', a space ship with movement controls and collision detection. This is half the game built, and although I some major refactoring as I've learnt more, these core parts of the game have remained largly untouched.

The game engine that astro runner uses is 100% Apple UIKit, there are no 3rd party frameworks or toolkits. There are also very little images and graphical assets. Apart from the application icon and the retro typeface, all the graphcial components are drawn in realtime with Core Graphics, this has kept the total download size to kjust under 300Kb, that's tiny compared to many other games, which easily run above 100Mb.

Head Banging weird Mountain Lion Network Issues

Okay, so the recent Mountain Lion Install went fairly smoothly with only a nfew hiccups. That was until I tried to update my blog post …

At first, everything worked as expected, but when I tried to update a longer post, the POST just timed out. I wan't too upset, it's my own bloging engine, so I just assumed my code would at fault. Later, I noticed a few other wweb pages weren't working either, and not samll sites, big ones, like facebook.com and apple.com, even apples disscussions.apple.com wouldn't load, and Dropbox had stopped syncing. Something was very wrong. Anyway, I was at work and couldn't spend all day fixing my MacBook, so I just switched to my iMac, still running Lion, everything was fine. Obviously a bug in the initial version of the OS.

Later at home, I fired up my MacBook, to try and resolve the problem. Everything worked fine. All of my problems at work just didn't manifest on my home network.

Next day, back at work, and the problems were all back, execectly the same. Now I had a very Mountain Lion specific bug only on the network at work, without any clue as to what was going on.

The Solution

A bit searching later, I stumbled across this post by Matt, from 2011, about imporving network performance by changing the Hardware MTU setting. His post does a great job explaing what the MTU does and how it effects netowrk traffic. So, I gave it a go to see if it would help.

The basic test to try is to send a TCP ping packet to a server, in my case the aunty beeb. The import part is setting the size, in bytes, of the packet and not allowing the payload to be spread of mutliple packets. This gives you your network MTU.

ping -c 2 -D -s 1464 bbc.co.uk

If the command Timesout, try lowering the -s. If the command pings back correctly, try upping the -s flag. The tick is to use the figure + 28 in your network settings.

Now, even though Mountain Lion shoudl be able to autodetect this, apparenetly its not as good as Lion was. By changing my MTU (in Preferences->Network->Advanced->Hardware), from 1500, to 1490, everything works fine. In fact, its better than fine, it's now pretty quick!

Now, i'm hoping this is only a temporary fix, and that the first service update to Mountain Lion fixes the autodetection, as i really dont want to have to check the MTU of every network I join!

Setting up a Ruby/Rails Environment in Mountain Lion

So, I've just backed up about 500Gb of stuff on Laptop, formatted the HD, and installed Mountain Lion from the Recovery partition, all fairly simple, a bit time consuming , but I like to have a completely fresh system for new OS installs, and overtime I've been streamlining my approach.

First off, Xcode

Make sure you've got the latest Xcode, currently 4.4, then after that installs, you'll need to enable command line tools, Xcode -> Preferences -> Downloads

That should be all of Xcode setup and working for development, however, if you plan on using ruby 1.9.2 or earlier, you'll also need to install gcc-4.2 separately (via HomeBrew)

Homebrew

[HomeBrew][http://mxcl.github.com/homebrew] has become my standard package manager on OS X, It's pretty simple to setup, and works well out of the box

/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

GCC

As Xcode no longer installs gcc, you'll have to install it manually before any ruby before 1.9.3. First you need to enable the homebrew-dupes repository, which gives you access to builds of Apples Open Source tools.

brew tap homebrew/dupes
brew install apple-gcc42

Databases

For now, we'll just setup MySql and Postgres as SQLite is included in OS X.

MySql is easy:

brew install mysql

Postgres is a bit more troublesome, and there appears to be a bug at the moment with Mountain Lion, which the current 'workaround' is to install without ossp-uuid. This works for me at the moment, but I'll be checking to see when this gets fixed.

Both databases will still require a bit more setting up, the commands to run will be output to the screen after you install them.

brew install postgresql --without-ossp-uuid

There will probably be plenty of other tools you'll need to install, but for me, the last big one is ImageMagick.

brew install imagemagick

This will prompt you to install Java (a necessary evil unfortunately).

RVM

All my rubies for development our managed by RVM, Very useful tool, and very simple to install.

curl -L https://get.rvm.io | bash -s stable --ruby

So, that should be enough to get a decent working development environment for Ruby/Rails projects, obviously you'll need to install rails and other project dependencies with bundler, but hopefully you be pretty used to those commands.

XQuarts

[XQuarts][http://xquartz.macosforge.org/landing] is needed if you plan on doing anything X11 related, just down and run the installer

Installing old Rubies with RVM

So, they setup earlier works fine for installing new rubies (i.e., 1.9.3), but it doesn't work so good for 1.8.7 and its bretheren. Now, I know these are old, and and you really shouldn't be using them anymore, but I still work on some old projects that require them. A simple change to your login environment should do the trick:

# in ~/.bash_profile or ~/.zshrc
export CC=/usr/local/bin/gcc-4.2
export CPPFLAGS=-I/opt/X11/include

Controlling Database Servers for a more efficient MacBook

Having a quick development environment means, obviuosly means being able develop ideas quicker. It should be in every programmers interest to understand the impact of project dependencies on speed and effiecentcy. Database servers are things we all need running when we're working, but rarely do we turn thme off when we're not. They just sit in the background. Now, it wouldn't be such an issue if it was only one, say Postgres, but recently i've also been using MySQL, Redis, Solr … to name a few, but still way too many!

One big issue is that most Database servers assume they're the only one you have installed, and asume you want them running all the time. Case in point, installing Postgres via HomeBrew, give you instructions to setup Launch Control to automatically start Postgres on boot, or it porovides you the command to run Postgres as a Daemon. Personally, non of these makes much sense from a development point of view. I want to run Database in much the same way as I run developemnt webservers, spin them up for coding, then kill them when i'm done.

Enter Foreman

Foreman is a Process Manager, when started, it reads from a Procfile and fire up the processes defined. This means I can run Foreman, which will then run all my project dependencies, including database server.

web: unicorn
database: Postgres -D /usr/local/var/postgres
delayed_job: ...

For me, including all my project runtime dependencies, including databases, into a process manager means I know that what I'm running in development is as close as possible to production (without using virtual machines). As a bonus, it also means i can turn off all the background daemons like Postgres or MySQL when I'm not doing any coding, which means my aging MacBook runs a bit smoother.

Why I've written my own Ruby test vim-script

One reason for choosing Vim as my new code editor is Vims excellent support for scripting. Vim-script pretty much allows you to customize the entire experience, as well as allowing many custom functions to make you more productive.

Learning the basics of vim-script is fairly easy (assuming you have some knowlegde of programming), and most of it is based around calling functions that operate on the current document. Therea are plently of vim-scripts available to download from http://www.vim.org or from online repos like http://github.com.

As an excuse to learn the language a but more, I've started to write my own scripts to better handle my workflow.

RunSpec()

RunSepc() is a simple vim-script to run Ruby RSpecs. It's pretty simple and demostrates a few of the basic ideas of calling functions and passing variables.

  " Checks to see if the passed in file exists, then runs the rspec command line program
  function! RunSpecFile(file)
    if filereadable(a:file)
      " Executes:
      " Clear the Screen
      " Print the Spec filename
      " Run rspec (in the context of bundle)
      exec '!clear && echo ' . a:file  ' && bundle exec rspec --color ' . a:file
    else
      echo "File " . a:file . " does not exist"
    endif
  endfunction

" The command to run, this figures out if the current file is a spec file. " Then it calls the RunSpecFile() passing in the current file, or the related spec file. function! RunSpec() " expands the special vim variable % to the full path of the current file let currentFile = expand('%') if IsSpecFile(currentFile) call RunSpecFile(currentFile) elseif IsCodeFile(currentFile) let specFile = CodeToSpecFile(currentFile) call RunSpecFile(specFile) end endfunction

" Maps the keybinding 's' (which for me is ',s') to call the function RunSpec() map s :call RunSpec()

" very simple regex on the current filename to see if starts with 'spec/...' function! IsSpecFile(file) return match(a:file, '^spec/') != -1 endfunction

" very simple regex on the current filename to see if its not a spec file and is a ruby file function! IsCodeFile(file) return !IsSpecFile(a:file) && (match(a:file, ".rb") != -1) endfunction

" Used to see if the current file is in a special Rails directory function! IsRailsAppFile(file) return match(a:file, '<controllers>|<models>|<views>') != -1 endfunction

" rewrites the file name from a code filename to a spec filename function! CodeToSpecFile(file) let specFile = a:file if IsRailsAppFile(a:file) let specFile = substitute(specFile, '^app/', '', '') endif let specFile = 'spec/' . substitute(specFile, '.rb$', '_spec.rb', '') return specFile endfunction

" rewrites the filename from a spec filename to a code filename function! SpecToCodeFile(file) let codeFile = substitute(a:file, '_spec.rb$', '.rb', '') let codeFile = substitute(codeFile, '^spec/', '', '') if IsRailsAppFile(a:file) let codeFile = 'app/' . codeFile endif return codeFile endfunction

The process here is very simple, each part of logic is split into function calls for reuse. It's also very specific to how I work, I know there are other vim-scripts that do a lot more then mine, however, half the fun of using vim is about customizing it to how I work and my needs. I don't use TestUnit (well, I dont at the moment), so why have the ability to run test unit files? I've found that taking this approach means I only install what I need, and I'm more eager to learn the built in way first.

Things I've learned writing this

Variables are assigned by using let, and need to use let when updating their value.

Variables can be scoped by appending a: to the name, e.g., 'a:myvar' refers to a function arguemnt called myvar. 'g:myvar' world refer to a global variable 'myvar'. There are a few others, e.g., 't:' will make the variable available within the current Vim Tab

Switching From Bash to Zsh

As part of my new new workflow, I'm also swithcing my shell, from Bash, to Zsh.

Bash has served me very well over the years, but its time a for a change. Having heard many good things about Zsh, I decided to take the plunge. The easiest and simplest way to get a working zsh shell is downloading oh-my-zsh by Robby Russell. It's very featured and has lots of plugins and themes. However, I've deceided to roll my own configuration using the already installing z-shell that comes with Mac OS X/Darwin. So, to start with:

        chsh -s /bin/zsh

It's that simple, your previous bash profile is still available should you choose to switch back. I'll let you figure out how to that!

Switching form Textmate to VIM

Or how i learned to stop worrying and love the command line

For many, many years, I have been happily coding in Textmate. A program that hasn't seen any upgrades for a long time. That is, untill the version 2 alpha was released just before christmas. However, this post isn't about really about Textmate, it's about how I turned to the dark side, installed VIM, and for the first time in in atleast 5 years, learned how to use a new text editor.

Now, let me just get one thing straight, I still love Textmte. It's an amazing tool that has served me very well for many years. It's excellent bundle support has made always to the rescue when i've need them. I've used Textmate everyday for most of my career, and I'm sure i'll continue to use it everyday.

So why switch to now? and why switch to VIM? why not SublimeText2? well, I have actually been using SublimeText2 over the past 2 months, and have been very impressed with it. It's quick, supports Textmate bundles and looks beautiful. It also has a command mode, called vintage, which behaves a lot like VIM. With SublimeText2, i thought I'd found the perfect middle ground, Textmates style, and VIMs commands, a very active development cycle and community. But, whilst using SublimeText2, I noticed that I was using the command mode more and more, and quite liking it, but not liking the limitations or a half baked emulation of VIM. So, one day, last week, i just thought, why not switch to VIM, full time, personal and professional … and cold turkey!

First things first … Installing VIM

I should also point out that I'm using Mac OS 10.7, so these command will all be very mac based, and will probably make assumptions like you already have things homebrew installed.

The easiest and safest option is to download the latest version from https://github.com/alexlovelltroy/macvim/downloads, this will have all required bits compiled, as well as using its own UI, it also has familier keyboard shortcuts.

The next step that everyone will tell you to do is to install Janus (https://github.com/carlhuda/janus). Janus is suite of VIM plugins that gives VIM loads of Textmate style functionality. So, I installed Janus, and basked in the glory of using familiar commands in my new VIM editor.

But I quickly realised that VIM is not textmate. My coding habits and Textmate familiarity just dont make sense with VIMs command based input. Janus is good if you want everything done for you, but it also does a lot of other stuff you probably dont want or need. This adds a lot of bulk to what is supposed to be a really light text editor. For me, Janus just doesn't make sense. I want to learn and use VIM the way VIM is supposed to used, not try and get VIM to work like Textmate. If i wanted Textmate, then I might as well have stayed working with Textmate! Janus showed me a lot cool things, but ultimatly it had to go. I want to make VIM fit me perfectly, not make me fit someone elses idea of what I should use.

Right now, I'm using a bare bones basic install of MacVim. the only plugin I have installed is Pathogen, which is a plugin management tool. As I code, I'm sure I'll be installing more plugins, but until I feel I realy need them, I'm quite happy to learn the core tools of VIM, that way, I'll be better actually using VIM, keep VIM lean and quic and only install things that i'll actually use.

© 2011–2024 Philip Balchin | About | sitemap | Colophon | RSS | π