Ben Clark-Robinson | Page 2

CAEmitterLayer: use to create particle effects. Each particle is an instance of CAEmitterCell. (10.6) – cocoadevcentral

How could you not be intrigued? Particle Effects! Well I’ve always been interested in Particle Generators, and there’s one right here in Snow Leopard. How exciting. /claps.

I recently took a look at the Fire and Fireworks sample code that Apple and was duly impressed by what Core Animation provides for so little cost both code-wise and CPU resources. So I decided to write the simplest – barebones – CAEmitterLayer code where I was only dependant on the NSView it draws on.

There’s no fancy-pants stuff going on here, just a raw, simple, single particle effect. But it gives you a great perspective on how it works and the minimal code required to have a great particle animation.

If you’re starting afresh you’re going to need to tell your project that we want to use Core Animation so:

  • Right click the Frameworks > Linked Frameworks on the left,
  • Add > Existing Frameworks…
  • Scroll to QuartzCore.framework > Add,
  • And make sure your ParticleController header file contains #import .

Looking at CAEmitterLayer briefly (and ignoring setting up Interface Builder & the Nib) in our header file we simply need a CAEmitterLayer:

IBOutlet NSView *view;
CALayer *rootLayer;
CAEmitterLayer *emitter;

Where as the implementation file is going to need a whole lot of data for the Emitter plus we need to create a CAEmitterCell for the particle itself.

//Create the emitter layer
emitter = [CAEmitterLayer layer];
emitter.emitterPosition = CGPointMake(CGRectGetMidX(rootLayer.bounds), CGRectGetMidY(rootLayer.bounds));
emitter.emitterMode = kCAEmitterLayerOutline;
emitter.emitterShape = kCAEmitterLayerCircle;
emitter.renderMode = kCAEmitterLayerAdditive;
emitter.emitterSize = CGSizeMake(50 * multiplier, 0);
//Create the emitter cell
CAEmitterCell* particle = [CAEmitterCell emitterCell];
particle.emissionLongitude = M_PI;
particle.birthRate = multiplier * 1000.0;
particle.lifetime = multiplier;
particle.lifetimeRange = multiplier * 0.35;
particle.velocity = 180;
particle.velocityRange = 130;
particle.emissionRange = 1.1;
particle.scaleSpeed = 0.3;
CGColorRef color = CGColorCreateGenericRGB(0.3, 0.4, 0.9, 0.10);
particle.color = color;
particle.contents = (id) [self CGImageNamed:@"spark.png"];

For the complete implementation file or the complete project please feel free to grab the source code from the bitbucket project.

At least just for my own notes here’s some iPad/iPhone user-agent string:

iPad 3.2 beta 2 (7B320c)

mozilla/5.0 (ipad; u; cpu os 3_2 like mac os x; en-us) applewebkit/531.21.10 (khtml, like gecko) version/4.0.4 mobile/7b320c safari/531.21.10

iPhone 3.1.3 (7E13) – Simulator

mozilla/5.0 (iphone simulator; u; cpu iphone os 3_1_3 like mac os x; en-us) applewebkit/528.18 (khtml, like gecko) version/4.0 mobile/7e18 safari/528.16

At first I was thrown by the Phusion Passenger installation instructions when it talked about enabling the Passenger module in apache .conf file. In Ubuntu the enabling/disabling of modules does not sit in a .conf file but, in fact, split into individual .load/.conf files in the /etc/apache2/mods-available folder.

This means when you enable a module with a2enmod in Ubuntu it simply makes a symlink from mods-enabled -> mods-available and disabling a module (with a2dismod is just as easy. No more hunting in those .conf files.

So I wanted to keep things using the same idea of using the mods-enabled directory as opposed to using one large apache2.conf file.

Phusion Passenger Installation

Passenger is drop dead simple to install, here’s the steps.

Update the system

sudo apt-get update
sudo apt-get install apache2-prefork-dev

Now Install Phusion Passenger

sudo gem install passenger
sudo passenger-install-apache2-module

Passenger is now installed; let’s get it enabled.

Create the .load/.conf in mod-available

Create the .load file with sudo nano /etc/apache2/mods-available/passenger.load and paste in the following:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9/ext/apache2/

Note: The version numbers I’ve used might not be what you have installed; Passenger will give you the correct version numbers on screen once installation is complete.

Create the .conf file with sudo nano /etc/apache2/mods-available/passenger.conf and paste in the following:

   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9
   PassengerRuby /usr/bin/ruby1.8

Enable Passenger

Enabling Passenger is as simple as:

sudo a2enmod passenger
sudo /etc/init.d/apache2 restart

And you will need to change your /etc/apache2/sites-available/default to read:

    DocumentRoot /webapps/rackapp/public

And you’re done. You’re up and running with Phusion Passenger.

You can read more about configuring Passenger here

I am unable to get Capistrano to deploy from our Subversion repository as it’s on a local IP, with no VPN access or access from the outside world and I’m also not in a position to open up the SVN box to the outside world.

So how does Capistrano get access to the source code?

Turns out it’s not that hard, you just need to know the tricks. So open up your /config/deploy.rb file and add/modify the following lines:

set :scm, :none
set :respository, "."
set :deploy_via, :copy

Using Capistrano

Here’s my notes for getting Capistrano up and running. You need only run these steps the first time:

sudo gem install Capistrano
cd /your/project/directory
capify .

copy deploy.rb (listed below) over project/config/deploy.rb

cap deploy:setup
cap deploy:cold

Subsequent Capistrano usage needs only:


Below is the deploy.rb I’ve used (many thanks to aussiegeek on twitter). You might not require the first line default_run_options[:pty] = true I had to add it for use on Ubuntu 9.10.

Also I’m using Phusion Passenger.

default_run_options[:pty] = true
set :application, 'projectName'
set :deploy_to, '/server/path/'
set :user, 'username'
set :use_sudo, false
role :web, ""
role :db, "", :primary => true
role :app, ""
set :scm, :none
set :repository, "."
set :deploy_via, :copy
namespace :deploy do
  task :start, :roles => :app do
  task :stop, :roles => :app do
  task :restart, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"

Here’s a list of BlackBerry Smartphones, their model, name, screen resolution and their video playback capabilities.

H.264 notes

It’s often difficult to determine the specific H.264 profiles that a BlackBerry can support, such as what’s the max bit-rate the device can handle? Looking at the specification pages for each model can assist; such as Bold 9700 specs

It’s a pretty safe bet to encode for baseline profile for a video, otherwise you might see a blank screen when you try and play it back. Take a look here for more on ffmpeg encoding for BlackBerry.

BlackBerry Models and capabilities

Blackberry® Model Resolution
BlackBerry 8100 240×260 MPEG4 Pearl
BlackBerry 8110
BlackBerry 8120
BlackBerry 8130
BlackBerry 8220 240×320 MPEG4 Pearl Flip
BlackBerry 8230
BlackBerry 8300 320×240 MPEG4 Curve
BlackBerry 8310
BlackBerry 8320
BlackBerry 8330
BlackBerry 8350i
BlackBerry 8520 320×240 H.264 Curve
BlackBerry 8530
BlackBerry 8800 320×240 MPEG4
BlackBerry 8820
BlackBerry 8830 320×240 H.264
BlackBerry 9000 480×320 H.264 Bold
BlackBerry 9500 360×480 H.264 Storm
BlackBerry 9530
BlackBerry 9550 360×480 H.264 Storm 2. OS 5.0
BlackBerry 9520
BlackBerry 9630 ? H.264 Tour
BlackBerry 9700 480×360 H.264 Bold 2. OS 5.0

Blank values mean they carry down from the model prior.

Sometimes ffmpeg just doesn’t play like you’d hope it would. I was trying to re-encode video clips for a BlackBerry Bold (the Bold supports H.264 playback) but every encode would have a blank black screen for video, and the audio would be fine (more on audio later).

I’m currently using SVN release r19352 (and also tested with r21566 (2010-01-31)).

ffmpeg arguments for BlackBerry H.264

ffmpeg -v 0 -y -i input.mp4 -f mp4 -aspect 2.409 -vcodec libx264 -vpre default -vpre baseline -s 480x200 -r 24 -b 220k -acodec libmp3lame -ab 24kbit/s -ac 1 output.mp4

So lets break down these arguments:

-v 0 = Set verbosity level
-y = Overwrite existing file
-i input.mp4 = The file you want to convert
-f = Force the video type
-aspect = The magical number to get the resize right
-vcodec libx264 = We're going to use x264 for video codec
-vpre default
-vpre baseline = Magical presets. And ensure BlackBerry compatibility
-s = The final dimensions of the clip
-r = Video frame rate
-b = Bitrate per second (the larger number the better the video)
-acodec libmp3lame = See Audio heading below
-ab = Audio bitrate
-ac 1 = Number of Audio Channels
output.mp4 = The output file

-vpre isn’t working for me (and I’m on Windows)

ffmpeg isn’t a Windows only application and looks for its presets in /usr/local/share/ffmpeg/ so if you create a folder structure on your Windows computer c:\usr\local\share\ffmpeg\ and copy all the *.ffpreset files into said folder you won’t have problems with -vpre anymore

Audio issues (AAC)

In later releases of ffmpeg AAC (or libfaac) was disabled; I assume due to AAC being patent encumbered. There’s ways around turn libfaac back on, or you could just switch to using libmp3lame or the like.

Here’s the steps I took to install Ruby on Rails on a fresh Ubuntu 9.10 Karmic Koala.

Update/upgrade system

sudo apt-get update

Install ruby, irb and rdoc

sudo apt-get install ruby irb rdoc

Install required Ubuntu packages

sudo apt-get install libopenssl-ruby build-essential ruby1.8-dev libpq-dev

Install rubygems

wget tar -xvzf rubygems-1.3.5.tgz cd rubygems-1.3.5/ sudo ruby setup.rb

sudo gem update --system

Install Rails (with gem)

sudo gem install rails

If you need to install postgresql

sudo apt-get install postgresql

Create the postgres user
sudo su postgres

Need to create a postgres database?

Install the ruby to postgres driver

sudo gem install postgres


That’s it, Ruby on Rails should be installed along with Postgresql if you need it.

Credit goes to Peter Vandenabeele for the basis for these steps.

Having connected a 3rd party (Polyview) 19″ LCD into the work MacBook Pro I was struck by how poor any on screen text rendered. Trying to use was just aweful, all jaggy and hard to read.

It turns out that font smoothing (aka sub-pixel antialiasing) on the 3rd party screen wasn’t happening and OS X was defaulting the font smoothing to CRT. Take a look at the screenshots below, bad eh?

Antialiasing for CRTs, ewwwww. Antialiasing fixed!

How to fix the problem?

Open up terminal and paste in the following:

defaults -currentHost write -globalDomain AppleFontSmoothing -int 2

or if you find the text a little large/blurry you can try:

defaults -currentHost write -globalDomain AppleFontSmoothing -int 1

Now logout > login.

So what’s up?

The whole Snow Leopard font smoothing issue seems strange and why Apple changed the font smooth dialog is beyond me. But you can read more about it here
jjgod / blog > Snow Leopard vs. 3rd Party LCD Displays if you’d like to know a little more about the problem.

Here’s my Mercurial .hgignore template for xcode/cocoa projects.

syntax: glob
# Backup files left behind by the Emacs editor.
# Lock files used by the Emacs editor.
# Temporary files used by the vim editor.
# Temporary files used by TestMate
# build directories
# XCode user data
# documentation
# for those crazies using svn and hg at the same time

I’ve recently been looking at hosting a complex JBoss/Apache project at Rackspace Cloud as opposed to our own servers+pipe at work.

I had changed the application to deliver the files from a CDN (in this case Rackspace Files) but thought “well Rackspace Cloud might be on the same pipe(s) as Files and could kill two birds with one stone”.

Essentially I wanted to know the pipe difference between Rackspace Cloud Servers and Rackspace Files and if Cloud was fast enough do away with Files.

The Test

Here’s some very rudimentary results where I download a 9.6 MB zip file.

Rackspace Cloud – Average download speed: 335 kb/s – Time: 27 seconds.
Rackspace Files – Average download speed: 1154 kb/s – Time: 8 seconds.

I used curl -O http://.../ for the download test.


Rackspace Cloud doesn’t use the same “pipes” as Rackspace Files (I’ve never read that Rackspace claim, “Cloud is as fast as Files” I wasn’t expecting the same results, just curious).

A dedicated CDN is the best way to go for delivery of large files quickly. (Rackspace Files uses the Limelight Network). I’ve heard rumours that Rackspace has Australian edge(s) and this seems to be the case.

I will still want to use Rackspace Files for large content delivery.


I use TPG ADSL2+ at home and never seen downloads faster than 1250-1300 kb/s. Using a 2.16GHz Macbook Pro.

At the time of writing: Rackspace Cloud Server is a cloud server hosting infrastructure. Rackspace Files is a Content Delivery Network.

Back to top