The Good Thing ™ to do is to use OS X’s built-in mechanism to start and keep processes running, namely launchd.
What we have to do is simply to write a plist containing the info needed by launchd, namely:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>at.eternalstorms.gstlauncherdaemon</string> <key>ProgramArguments</key> <array> <string>/Applications/GimmeSomeTune.app/Contents/MacOS/GimmeSomeTune</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Save this as a plist file in ~/Library/LaunchAgents. The name doesn’t really matter, but the best way to keep everything tidy and adhere to OS X’s standards is to call it at.eternalstorms.gstlauncherdaemon.plist.
Alright! Now GimmeSomeTune is going to start when you log in, and launchd will make sure it keeps running (i.e. relaunch it if it crashes). To tell launchd to use that plist file right now without having to log out and back in again, run:
launchctl load -w ~/Library/LaunchAgents/at.eternalstorms.gstlauncherdaemon.plist
And conversely, to stop it:
launchctl unload -w ~/Library/LaunchAgents/at.eternalstorms.gstlauncherdaemon.plist]]>
The MBA feat is achieved through “deep sleep”, i.e. writing the RAM contents to a file on the hard drive, which allows powering down the RAM without losing state (also known as hibernation). The only problem is that waking the computer up requires loading back all of this data on RAM, which takes a few seconds.
Apple even uses a trickier approach by default: the computer sleeps normally at first, and switches to deep sleep after a certain amount of time.
This is very easy to see on the MBA: close the lid and reopen it a few minutes later, waking up is super fast. Leave it sleeping for a day, and it will take about ten seconds before you can do anything with it.
While this is a clever solution, the parameters aren’t that well adjusted â the computer goes to deep sleep too fast in my opinion.
This can be modified through pmset. First, run it to see what are the active parameters:
Air:~ florent$ pmset -g Active Profiles: Battery Power -1* AC Power -1 Currently in use: deepsleepdelay 4200 halfdim 0 hibernatefile /var/vm/sleepimage disksleep 10 sleep 10 hibernatemode 3 displaysleep 5 ttyskeepawake 1 deepsleep 1 acwake 0 lidwake 1
The interesting one is deepsleepdelay (edit: see footnotes). It represents the time in seconds before switching from classical sleep to deep sleep. 4200 seconds, 70 minutes, is way too short. Let’s set it to 24hrs instead:
Air:~ florent$ sudo pmset -a deepsleepdelay 86400
There it is! Deep sleep will still work, but won’t be as annoying.
Edit July 2, 2011:
It looks like Apple changed the name of that setting from deepsleepdelay to standbydelay during the update to OS X 10.6.8. The command line has to be changed accordingly:
Air:~ florent$ sudo pmset -a standbydelay 86400]]>
The closest thing to a solution that I found is through Character Style:
– Select a piece of text, make it semibold
– In the Styles Drawer, under Character Styles, click on the little arrow next to “none” and “Create New Character Style From Selection”
– Assign a Hot Key to the newly created Character Style, by clicking the arrow next to it and Hot Key.
There are a few drawbacks to this approach, mainly that the character style you’re defining will be tied to a particular font, and that the only shortcuts allowed by the Hot Key setting are F1 to F6. If anyone has a better way, I’m all ears!
]]>How to fix that? Let’s relaunch it as soon as it crashes. Simple!
In a terminal:
for (( ; ; )); do open -W /Applications/Multimedia/GimmeSomeTune.app/; done
open is the bash command to launch applications on OS X. It works with all kinds of files: open somefile.avi will open that file in your default video player, VLC for example. The -W flag tells open to wait until the application exits before returning any value. By putting it all in a for loop, we effectively ensure that bash will launch GimmeSomeTune, wait until it crashes, then relaunch it, and so on.
Edit: this is a bad way of doing things. A better way is described here.
]]>The solution I used was simple: instead of having Apache listening on port 80, I set up nginx to listen to port 80 and redirect to either Apache (set to listen on port 8080 instead) or Sinatra (port 9393) depending on the URL.
Nginx configuration was dead simple (after a few tries). The gist of it being these few lines:
location / { proxy_pass  http://127.0.0.1:8080/; } location /reorg { proxy_pass http://127.0.0.1:9393; }
The configuration in its entirety is available here.
After setting up this solution, I realized Apache’s mod_proxy would have done the trick without the need for nginx. And that mod_rack (Phusion Passenger) could probably have eliminated the need for running a specific ruby process for Sinatra at all. Live and learn!
]]>The Finder correctly reports these new .aplibrary as “Aperture Library”, but it seems to have forgotten everything about the old .approject who now appear as standard folders (it appears to be a weird bug on my machine, but still).
So how do we convert our .approject to .aplibrary?
That’s it! Quite straightforward indeed, but a bit puzzling at first.
]]>And it rocks.
]]>My stacktrace on Mac OS X Snow Leopard 10.6.6 with Rubygems 1.4.2, Ruby 1.8.7 and Postgres 9.0.2 was the following:
Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb checking for pg_config... yes Using config values from /usr/local/bin/pg_config checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for PQconnectdb() in -lpq... no checking for PQconnectdb() in -llibpq... no checking for PQconnectdb() in -lms/libpq... no Can't find the PostgreSQL client library (libpq) *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Oookay, so let’s try to find out what’s going wrong. A quick Google search shows that errors like this one happens on Linux too, and usually suggests that ARCHFLAGS definitions may be a problem. Indeed, /Library/Ruby/Gems/1.8/gems/pg-0.10.1/ext/mkmf.log contains this error message:
ld: warning: in /usr/local/Cellar/postgresql/9.0.2/lib/libpq.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
The problem seems to come from the way Homebrew installs Postgres.
Homebrew install notes include the following informative message:
If you want to install the postgres gem, including ARCHFLAGS is recommended: env ARCHFLAGS="-arch x86_64" gem install pg
There! Now the only problem is if you install your gems as root, you can’t merely put a sudo before the “gem”, but you have to sudo su then execute the command:
Air:~ florent$ sudo su Password: sh-3.2# env ARCHFLAGS="-arch x86_64" gem install pg Building native extensions. This could take a while... Successfully installed pg-0.10.1 1 gem installed Installing ri documentation for pg-0.10.1... Installing RDoc documentation for pg-0.10.1...
Voilà !
Edit 18 Dec. Chad provided a simpler solution in the comments that doesn’t require you to log in as root and works just as well:
sudo env ARCHFLAGS="-arch x86_64" gem install pg]]>
Tunalysis is a small(ish) Ruby script that will read your iTunes library, crunch numbers, and gives you a few interesting facts about it, such as:
Some of these statistics are already available in iTunes, but Tunalysis ultimate goal is to expand iTunes (limited) stats and to give you hindsight on your musical habits and tastes.
Tunalysis is written in Ruby and uses Bleything’s plist to parse iTunes’ XML library.
At the time being, Tunalysis only works on OS X. I’m not planning to do a Windows port, but will gladly accept a patch if you do. :)
Tunalysis is licensed under the GPLv3.
I’m open to suggestions. If you’re interested in a particular piece of data, leave a comment or send me an email and I’ll add it.
Get Tunalysis on GitHub!
]]>I don’t know why, but it never occurred to me to look for shortcuts in Terminal (and bash in general), other than Ctrl-c for badly behaving processes. I just cursed myself and frantically typed on the left arrow key each time I typed cd instead of cp.
Turns out bash has plenty of them, and here are a few useful ones I’m really glad to know now:
Beginning of the line: Ctrl+a
End of the line: Ctrl+e
Delete the word under the cursor or before: Ctrl+w
Delete all chars before the cursor: Ctrl+u
Delete all chars after the cursor: Ctrl+k
Apparently these shortcuts work in a lot of text fields, everywhere.
You can also move the cursor word-by-word by typing Esc, then f or b. It’s not really practical though, so you’d be better of remapping the following keys in Terminal Settings > Settings > Keyboard:
control cursor left: \033b (\033 is actually Esc)
control cursor right: \033f
Now you can swiftly move word-by-word with Alt+left arrow and Alt+right arrow.
I guess the lesson here is there’s always to learn from your siblings â especially the geeky ones.
]]>