March 25th, 2010
Ever needed your Cocoa/Objective-C application to Launch at Login? And also have your app appear in your users System Preferences > Accounts > Login Items list? Want this integration to be super-mega-piss-easy?
Well now you can.
We’re going to wrap LSSharedFileList to get our App to start at login – a Cocoa solution – as opposed to other solutions that use Carbon or having to edit XML system pref files.
Take a look at Github – Launch at Login for the source. Don’t forget to look at the readme for assistance for implementation.
Basically copy the LaunchAtLoginController.h/.m files into your project then either you can implement with Code or with Interface Builder.
Code
Will app launch at login?
LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init];
BOOL launch = [launchController launchAtLogin];
[launchController release]; |
Set launch at login state.
LaunchAtLoginController *launchController = [[LaunchAtLoginController alloc] init];
[launchController setLaunchAtLogin:YES];
[launchController release]; |
IB
- Open Interface Builder
- Place a NSObject (the blue box) into the nib window
- From the Inspector – Identity Tab (Cmd+6) set the Class to LaunchAtLoginController
- Place a Checkbox on your Window/View
- From the Inspector – Bindings Tab (Cmd+4) unroll the > Value item
- Bind to Launch at Login Controller
- Model Key Path: launchAtLogin
Easy right?
So what are you waiting for? Grab the code from Github – Launch at Login
Posted in Uncategorized | Comments Off
February 24th, 2010
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 <QuartzCore/QuartzCore.h>.
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;
CGColorRelease(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.
Tags: CAEmitterLayer, Core Animation
Posted in Apple | Comments Off
February 23rd, 2010
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 |
Posted in Uncategorized | Comments Off
February 17th, 2010
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/mod_passenger.so |
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:
<IfModule passenger_module>
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /usr/bin/ruby1.8
</IfModule> |
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:
<VirtualHost *:80>
ServerName www.rackapp.com
DocumentRoot /webapps/rackapp/public
</VirtualHost> |
And you’re done. You’re up and running with Phusion Passenger.
You can read more about configuring Passenger here
Posted in Ruby on Rails | Comments Off
February 15th, 2010
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:
deploy.rb
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, "server.com"
role :db, "server.com", :primary => true
role :app, "server.com"
set :scm, :none
set :repository, "."
set :deploy_via, :copy
namespace :deploy do
task :start, :roles => :app do
end
task :stop, :roles => :app do
end
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
end |
Posted in Ruby on Rails | Comments Off
February 2nd, 2010
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.
Posted in Uncategorized | Comments Off
February 2nd, 2010
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.
Posted in Uncategorized | 1 Comment »
January 15th, 2010
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 http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
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
createuser
Need to create a postgres database?
createdb
Install the ruby to postgres driver
sudo gem install postgres
Finished
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.
Posted in Ruby on Rails | 2 Comments »
January 14th, 2010
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 Terminal.app 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.
Posted in Apple | Comments Off
November 23rd, 2009
Here’s my Mercurial .hgignore template for xcode/cocoa projects.
syntax: glob
.DS_Store
# Backup files left behind by the Emacs editor.
*~
# Lock files used by the Emacs editor.
.\#*
# Temporary files used by the vim editor.
.*.swp
# Temporary files used by TestMate
._*
# build directories
**/build/*
build/*
# XCode user data
**.pbxuser
**.mode?v?
**.perspectivev?
# documentation
**.docset/*
# for those crazies using svn and hg at the same time
*.svn* |
Tags: Mercurial
Posted in Source Control | Comments Off