Put your mac to rest via ssh

Sometimes my Macbook decides to wake up from his sleep (a.k.a hibernation). Most of the times i notice this at work when my emails disappear from my imap inbox as Mail.app applies his rules.

As i do not have Apple Remote Desktop or any other VNC server enabled on my Macbook, i do have a problem.

I can vpn into my home and i can ssh into the Macbook, so i came up with the following solution:

Put the following three lines into a plain textfile, i.e. “sleep.txt” and save it somewhere:

tell application "Finder"
  sleep
end tell

Then, open Terminal.app, change to the directory you saved the file in and execute:

osascript sleep.txt

Your ssh connection will then timeout and the Mac sleeps.

Stupid me forgot that ssh can execute remote commands: From your workmachine execute

ssh my_home_computer 'osascript sleep.txt'

and you’re done. Thanks “tante” for reminding me 🙂

Alternatively, you can achieve similar with Mail.app itself, have a look at the solution here, but i like mine better.

| Comments (6) »

17-Jul-08


Firefox 3 Mouse Wheel Zoom

Zooming with the CTRL+Mouse Wheel Up/Down has been in inversed in Firefox 3. In version 2 you zoomed in (enlarged the text) with CTRL+Mouse Wheel Down and zoomed out with CTRL+Mouse Wheel Up, its now in Firefox 3 the other way round.

The revert back to the old behaviour, change

mousewheel.withcontrolkey.numlines = 1

to

mousewheel.withcontrolkey.numlines = -1

in about config.

To me “pulling” the page towards myself always felt much more natural to me than the other way round, but that’s just me.

| Comments (0) »

08-Jul-08


regex: URL thingy with username, password, host and port

Just in case i do keep forgetting that stuff, here’s a regex for decoding urls like

ftp://user:somepass@somehost:someport

in Java:

final Hashtable<String, Integer> portMap = new Hashtable<String, Integer>();
portMap.put("ftp", 21);
portMap.put("sftp", 22);
 
final Pattern urlPattern = Pattern.compile("(ftp|sftp)://(\\S+):(\\S+)@([\\S&&[^:]]+)(:(\\d+))?");
 
final Matcher m = urlPattern.matcher(url);
if(!m.matches()) 
	throw new RuntimeException("Invalid ftp url!");			
 
final String protocol = m.group(1).toLowerCase();
final String user     = m.group(2);
final String password = m.group(3);
final String host     = m.group(4);
final int port = m.group(6) != null ? Integer.parseInt(m.group(6)) : portMap.get(protocol);

Just in case anybody is interessted, i’m writing a wrapper around j2ssh and Commons::Net to support both ftp and sftp in a J2SE program.

| Comments (1) »

07-Jul-08


Rails 2.1: send_file :x_sendfile => true

The “x_sendfile” argument on the send_file method in Rails 2.1 is not well thought off as it has an impact in development mode also. I guess most Rails coders won’t have Apache proxying their mongrels in dev mode and so they don’t get to see any images or files but the plain path information.

I’ll guess i stay with the x_send_file solution as described here.

| Comments (0) »

05-Jun-08


Oracle XE environment variables on Linux

Just a quick reminder for myself:

With the default installation of an Oracle Express (Oracle XE) comes two shell script with all the necessary environment variables to use sql*plus, exp, imp and the like on the command line:

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh

respectively

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.csh

| Comments (0) »

04-Jun-08