Sunday, December 20, 2009

Browse the Google Chrome SQLite Database

1. Quit Google Chrome.
2. Open SQLite Database Browser.
3. File > Open Database.
4. Browse to ~/.config/google-chrome/Default/Web Data

Wednesday, December 16, 2009

Change the Login Screen Power Management Preferences on Ubuntu

1. sudo chsh -s /bin/bash gdm
2. sudo passwd gdm
3. Switch User
4. Login as gdm
5. System > Preferences > Power Management
6. Edit as desired
7. Close
8. Logout
9. Login as original user
10. sudo chsh -s /bin/false gdm
11. sudo passwd -d gdm
12. sudo vipw -s
13. Replace empty password field with '*' character
14. Save the file

I used this, for example, to disable suspend on closing the lid of my laptop.

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)

# 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

# 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

# $ ./ '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")'

    # 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 

Sunday, October 4, 2009

Return an Array from a Bash Function

Update 2009/12/01: I recommend the newer solution I posted today instead of the one below.

The following safely handles array elements containing spaces.  Other solutions I've found do not.

#! /bin/bash

# $ ./ 
# ./ line 9: declare: returned_array: not found
# declare -a returned_array='([0]="one" [1]="two three")'

    local -a an_array=( 'one' 'two three' )
    declare -p an_array

declare -p returned_array
eval $(return_an_array | sed -e 's/^\(declare -a \)[^=]*=/\1 returned_array=/')
declare -p returned_array

Saturday, October 3, 2009

Determine if a Bash script was Executed or Sourced

[ "$0" == "$BASH_SOURCE" ] && echo 'executed' || echo 'sourced'

Tuesday, September 29, 2009

cURL Login, Save and Use Cookies

curl -b cookiejar -c cookiejar -u 'username:password' 'http://login/form'
curl -b cookiejar -c cookiejar 'http://another/url/requiring/session/cookie'

Thursday, September 24, 2009

Set Environment Variables in Gnome on Ubuntu Linux

On Ubuntu 9.04 (and probably other versions),
  1. `/bin/sh /etc/gdm/Xsession default` reads ~/.profile
  2. /bin/sh is Dash, not Bash.  Dash accepts a subset of the syntax that Bash accepts.
  3. Environment variables set in ~/.profile or in files sourced by ~/.profile are propagated to Gnome and programs launched from Gnome.

Saturday, September 19, 2009

Set a breakpoint in a Bazaar plugin source file

(pdb) b /the/full/path/from/which/bzr/loads/the/plugin/source/

Thursday, September 17, 2009

Schedule something to run once

at now +1 minute
warning: commands will be executed using /bin/sh
at> echo 'do something'

Wednesday, September 16, 2009

General-purpose progress for moving data at the command line


Can replace cp or cat.

Sunday, September 13, 2009

Incremental git fast-export / fast-import

Initial export:
git fast-export --all --export-marks=exportmarks.txt >
Initial import:
git fast-import --export-marks=importmarks.txt 
Incremental export:
git fast-export --all --import-marks=exportmarks.txt --export-marks=exportmarks.txt >
Incremental import:
git fast-import --import-marks=importmarks.txt --export-marks=importmarks.txt 

Thursday, September 10, 2009

Configure P4V to use Beyond Compare

Edit > Preferences > Diff

External Diff Tool, e.g., Beyond Compare, in IntelliJ IDEA

File > Settings > IDE Settings: General > Diff Options

Wednesday, September 9, 2009

Command Line Remote Desktop

rdesktop -d DOMAIN -u USER -g WxH HOST

tsclient's clipboard was not working.  rdesktop's works.

Monday, August 31, 2009

te: command-line tool for editing tab-delimited text files

`te` is a nice tool for editing tab-delimited text files.

Find a package containing a file on .deb systems

`dpkg -S` searches for a file and tells you what package it's in.