set -o errexit # Exit on simple commands that return non-zero status.
set -o errtrace # Makes shell functions, command substitutions, and
# commands in subshells inherit traps on ERR
set -o nounset # Exit on use of unset variables.
Monday, February 1, 2010
Bash Options to Fail Fast
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
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.
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
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
Subscribe to:
Posts (Atom)
