Wednesday, December 16, 2009

Convert a Grayscale Photo to RGB so that iPhoto will Import It v. 2

I wrote an earlier post describing how to use ImageMagick to convert a grayscale photo so that iPhoto will import it. This method is simpler. The earlier method is better if you have a large number of grayscale photos to import.

1. Open the image in Preview.
2. Tools > Match to Profile...
3. Select Color Model: RGB
4. Select ColorSync Profile: Generic RGB Profile
5. OK
6. File > Save

Monday, December 14, 2009

Convert among date formats with date(1)

http://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html

# Now
$ date 
Mon Dec 14 15:09:51 EST 2009

# Relative dates
$ date -d 'yesterday'
Sun Dec 13 15:09:56 EST 2009

# Seconds since the UNIX epoch
$ date +%s
1260821405

# From seconds to the default format
$ date -d @$(date +%s)
Mon Dec 14 15:10:25 EST 2009

Monday, December 7, 2009

Tuesday, December 1, 2009

Return an Array from a Bash Function v. 2

I wrote an earlier post about returning an array from a Bash function. This version is better.

#! /bin/bash

# $ ./array_to_string.sh 'this' 'is a' 'test'
# declare -a output_array='([0]="this" [1]="is a" [2]="test")'
# declare -a output_array='([0]="this" [1]="is a" [2]="test")'

array_to_string()
{
    # Treat the arguments as an array:
    local -a array=( "$@" )
    declare -p array | sed -e 's/^declare -a array=//'
}

# Pass an array to a function:
input_array=( "$@" )
string="$(array_to_string "${input_array[@]}")"

# string_to_array idiom:
string_to_array_code="declare -a output_array=${string}"
eval "$string_to_array_code"

# The outputs of the following two commands should be identical:
echo "$string_to_array_code"
declare -p output_array

Friday, November 27, 2009

Convert a Grayscale Photo to RGB so that iPhoto will Import It

Update 2009/12/16: I wrote a more recent post about using Preview to convert a grayscale photo so that iPhoto will import it. That method is simpler. This method is better if you have a large number of grayscale photos to import.

Install ImageMagick.
convert photo_from_iphoto.jpg srgb.icm
convert photo_as_grayscale.jpg -profile srgb.icm photo_as_srgb.jpg

Tuesday, November 24, 2009

Unwrap text in Emacs

C-u 9 9 9 9 C-x f
C-x h
M-x fill-region

Thursday, November 12, 2009

SSH Port Forwarding

# Forward localhostport to destinationhost:destinationhostport
# using sshdhost.
#
# e.g, forward localhost:80 to remotehost:8080 using anysshdhost
# sudo ssh -L 80:remotehost:8080 user@anysshdhost
sudo ssh -L localhostport:destinationhost:destinationhostport user@sshdhost

# Forward sshdhost:sshdhostport to
# destinationhost:destinationhostport using sshdhost.
#
# e.g., forward localhost:80 to remotehost:8080 using localhost
# ssh -R 80:remotehost:8080 root@localhost
ssh -R sshdhostport:destinationhost:destinationhostport user@sshdhost