OS X version detection in Ruby
>> `osascript -e 'tell application "Finder"\nreturn version\nend tell'`.chop! => "10.5.3"
11381 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
>> `osascript -e 'tell application "Finder"\nreturn version\nend tell'`.chop! => "10.5.3"
alias rmdsstores='find ./ -type f | grep .DS_Store | xargs rm'
alias rmdsstores='find . -name *.DS_Store -type f -exec rm {} \;'
alias rmdsstores='find ./ -type f | grep .DS_Store | xargs rm'
#!/bin/sh curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.3.5.tar.gz tar xzvf freetype-2.3.5.tar.gz cd freetype-2.3.5 ./configure --prefix=/usr/local make sudo make install cd .. curl -O http://superb-west.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.22.tar.bz2 tar jxvf libpng-1.2.22.tar.bz2 cd libpng-1.2.22 ./configure --prefix=/usr/local make sudo make install cd .. curl -O ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz tar xzvf jpegsrc.v6b.tar.gz cd jpeg-6b ln -s `which glibtool` ./libtool export MACOSX_DEPLOYMENT_TARGET=10.5 ./configure --enable-shared --prefix=/usr/local make sudo make install cd .. curl -O ftp://ftp.remotesensing.org/libtiff/tiff-3.8.2.tar.gz tar xzvf tiff-3.8.2.tar.gz cd tiff-3.8.2 ./configure --prefix=/usr/local make sudo make install cd .. curl -O http://jaist.dl.sourceforge.net/sourceforge/wvware/libwmf-0.2.8.4.tar.gz tar xzvf libwmf-0.2.8.4.tar.gz cd libwmf-0.2.8.4 make clean ./configure make sudo make install cd .. curl -O http://www.littlecms.com/lcms-1.17.tar.gz tar xzvf lcms-1.17.tar.gz cd lcms-1.17 make clean ./configure make sudo make install cd .. curl -O ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/GPL/gs860/ghostscript-8.60.tar.gz tar zxvf ghostscript-8.60.tar.gz cd ghostscript-8.60/ ./configure --prefix=/usr/local make sudo make install cd .. curl -O ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/GPL/current/ghostscript-fonts-std-8.11.tar.gz tar zxvf ghostscript-fonts-std-8.11.tar.gz sudo mv fonts /usr/local/share/ghostscript curl -O http://imagemagick.site2nd.org/imagemagick/ImageMagick-6.3.5-9.tar.gz tar xzvf ImageMagick-6.3.5-9.tar.gz cd ImageMagick-6.3.5 export CPPFLAGS=-I/usr/local/include export LDFLAGS=-L/usr/local/lib ./configure --prefix=/usr/local --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8 --with-gs-font-dir=/usr/local/share/ghostscript/fonts make sudo make install cd .. sudo gem install RMagick
function gemdocs() { if [[ -n "$(whereis gem_server)" ]]; then gem_server >/dev/null 2>&1 & sleep 3 open http://127.0.0.1:8808/ fi }
# Usage: pman ls; pman getopts # convert a singel man page to a PDF file, save and open it pman 8 sticky # same with manual section number pman m toe pman -b ls 'open(2)' dd "chmod(2)" curl 'open(n)' # batch convert man pages into PDF files pman -p rm srm open\(2\) 'toe(m)' 'ncurses(3)' # print man pages using the default printer pman() { section="$1" manpage="$2" mandir="/Users/Shared/manpages" # save the created PDF man pages to the specified directory # batch process man pages to PDF files with the "-b" switch and save them to $mandir # example: pman -b ls 'open(2)' dd 'chmod(2)' 'open(n)' 'sticky(8)' # cf. man -aW open for "man n open" if [[ "$1" = "-b" ]]; then if [[ ! -d $mandir ]]; then mkdir -p $mandir chmod 1777 $mandir fi shift # remove "-b" from "$@" for manfile in "$@"; do # example for $manfile: open(2) manpage="`echo $manfile | grep -Eos '^[^\(]+'`" # extract name of man page section="`echo $manfile | grep -Eos '\([^\)]+\)' | grep -Eos '[^\(\)]+'`" # extract section of man page if [[ ! "$section" ]]; then section="1" fi if [[ ! -f "`man ${section} -W ${manpage} 2>/dev/null`" ]]; then #if [[ ! -f "`man -W ${section} ${manpage} 2>/dev/null `" ]]; then echo "No such man page: man ${section} ${manpage}" continue fi manfile="${mandir}/${manpage}(${section}).pdf" echo "$manfile" if [[ ! -f "$manfile" ]]; then man $section -t $manpage 2>/dev/null | pstopdf -i -o "$manfile" 2>/dev/null chmod 1755 "$manfile" # hide file extension .pdf if [[ -f /Developer/Tools/SetFile ]]; then /Developer/Tools/SetFile -a E "$manfile"; fi fi done return 0 fi # END of batch processing man pages to PDF files # print PDF man pages using the default printer (see man lpr and man lpoptions) # if necessary, create the specified PDF man pages and save them to $mandir # example: pman -p rm srm if [[ "$1" = "-p" ]]; then if [[ ! -d $mandir ]]; then mkdir -p $mandir chmod 1777 $mandir fi shift # remove "-p" from "$@" for manfile in "$@"; do # example for $manfile: open(2) manpage="`echo $manfile | grep -Eos '^[^\(]+'`" # extract name of man page section="`echo $manfile | grep -Eos '\([^\)]+\)' | grep -Eos '[^\(\)]+'`" # extract section of man page if [[ ! "$section" ]]; then section="1" fi if [[ ! -f "`man ${section} -W ${manpage} 2>/dev/null`" ]]; then echo "No such man page: man ${section} ${manpage}" continue fi manfile="${mandir}/${manpage}(${section}).pdf" echo "$manfile" if [[ ! -f "$manfile" ]]; then man -t $section $manpage 2>/dev/null | pstopdf -i -o "$manfile" 2>/dev/null chmod 1755 "$manfile" # hide file extension .pdf if [[ -f /Developer/Tools/SetFile ]]; then /Developer/Tools/SetFile -a E "$manfile"; fi lpr "$manfile" else lpr "$manfile" fi done return 0 fi # END of printing man pages using the default printer # convert a single man page to a PDF file, save it to $mandir and then open it in a PDF viewer if [[ -z "$1" ]] || [[ $# -gt 2 ]]; then # check number of arguments #if [[ -z "$1" || $# -gt 2 ]]; then #if [ -z "$1" -o $# -gt 2 ]; then echo "Wrong number of arguments!" return 1 fi if [[ ! "$manpage" ]]; then # turn "pman ls" into "pman 1 ls" manpage="$section" # if $manpage is an empty string because there has been no "$2" then $manpage is set to "$section" and ... section="1" # ... $section is set to "1" fi if [[ ! -f "`man ${section} -W ${manpage} 2>/dev/null`" ]]; then echo "No such man page: man ${section} ${manpage}" return 1 fi if [[ ! -d $mandir ]]; then mkdir -p $mandir chmod 1777 $mandir fi manfile="${mandir}/${manpage}(${section}).pdf" if [[ -f "$manfile" ]]; then open "$manfile" else man $section -t $manpage 2>/dev/null | pstopdf -i -o "$manfile" 2>/dev/null chmod 1755 "$manfile" # hide file extension .pdf if [[ -f /Developer/Tools/SetFile ]]; then /Developer/Tools/SetFile -a E "$manfile"; fi open "$manfile" fi return 0 }
# test after installation which psql # /usr/local/bin/psql psql --version # psql (PostgreSQL) 8.2.3, contains support for command-line editing
# test after installation ruby -v # ruby 1.8.6 rails -v # Rails 1.2.3 gem list # ... mongrel (1.0.1) ...
sudo gem install -y ruby-postgres
# first create a directory called PostgreSQL-db on your Desktop mkdir -p $HOME/Desktop/PostgreSQL-db # create a new db server called railsdb /usr/local/bin/initdb -E UTF8 -D $HOME/Desktop/PostgreSQL-db/railsdb # START DB SERVER dir="$HOME/Desktop/PostgreSQL-db"; /usr/local/bin/pg_ctl -D $dir/railsdb -l $dir/railsdb/postgres.log start # STOP DB SERVER #dir="$HOME/Desktop/PostgreSQL-db"; /usr/local/bin/pg_ctl -D $dir/railsdb -l $dir/railsdb/postgres.log stop -m smart # check cat $HOME/Desktop/PostgreSQL-db/railsdb/pg_hba.conf ... # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust
createdb `whoami`_development #dropdb `whoami`_development createdb `whoami`_test #dropdb `whoami`_test #createdb `whoami`_production #dropdb `whoami`_production
cd $HOME/Desktop/RubyOnRails-projects rails -d postgresql `whoami` cd `whoami`
open -e $HOME/Desktop/RubyOnRails-projects/`whoami`/config/database.yml # just uncomment the following line #encoding: UTF8
cd $HOME/Desktop/RubyOnRails-projects/`whoami` ruby script/generate migration People # edit /db/migrate/001_people.rb # cf. http://wiki.rubyonrails.org/rails/pages/TutorialStepOneMigrations open -e $HOME/Desktop/RubyOnRails-projects/`whoami`/db/migrate/001_people.rb class People < ActiveRecord::Migration def self.up create_table :people do |table| # note that "id" is added implicitly, by default table.column :name, :string table.column :street1, :string table.column :street2, :string table.column :city, :string table.column :state, :string table.column :zip, :string end end def self.down drop_table :people end end rake db:migrate ruby script/generate model Person #open -e $HOME/Desktop/RubyOnRails-projects/`whoami`/app/models/person.rb # file will be explained below ruby script/console >> ... entry = Person.new entry.name = "Name" entry.street1 = "123 Somwhere" entry.street2 = "" entry.city = "Smallville" entry.state = "KS" entry.zip = "123456" entry.save exit # check newly created db table psql `whoami`_development SELECT * FROM people; \q # test rake # ... 0 failures, 0 errors # create new controller ruby script/generate controller People list view new edit # edit /app/controllers/people_controller.rb open -e $HOME/Desktop/RubyOnRails-projects/`whoami`/app/controllers/people_controller.rb def view @person = Person.find(1) end # edit /app/views/people/view.rhtml open -e $HOME/Desktop/RubyOnRails-projects/`whoami`/app/views/people/view.rhtml # copy & paste & uncomment the following lines #<html> # <body> # <h1>People#view</h1> # <p>This page will display one person.</p> # <p> # <%= @person.name %><br /> # <%= @person.street1 %><br /> # <%= @person.street2 %><br /> # <%= @person.city %><br /> # <%= @person.state %><br /> # <%= @person.zip %><br /> # </p> # </body> #</html> # the file /app/models/person.rb explained (see above) # open -e $HOME/Desktop/RubyOnRails-projects/`whoami`/app/models/person.rb # class Person < ActiveRecord::Base # end # How does this know to map to the people table we created? ActiveRecord pluralizes the class name and looks for that # table in the database. This doesn’t just mean adding an ’s’. Irregular plural forms are also handled, so Rails knows # that the plural of ‘person’ is ‘people’. The rules for how it does this are described in the documentation # (see http://wiki.rubyonrails.org/rails/pages/TutorialStepSix). # test rake # start your Rails app cd $HOME/Desktop/RubyOnRails-projects/`whoami` ruby script/server #ruby script/server --environment=development # open a second shell window and go to ... open -a Safari http://localhost:3000/people/view
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd > <plist version='1.0'> <dict> <key>Label</key><string>com.automatthew.php</string> <key>ProgramArguments</key> <array> <string>/opt/php/bin/php</string> <string>-b 127.0.0.1:9000</string> <string>-q</string> </array> <key>EnvironmentVariables</key> <dict> <key>PHP_FCGI_CHILDREN</key> <string>4</string> </dict> <key>Debug</key><false/> <key>Disabled</key><false/> <key>OnDemand</key><false/> <key>RunAtLoad</key><false/> </dict> </plist>
# move cursor to beginning of line cr = "\r" # ANSI escape code to clear line from cursor to end of line # "\e" is an alternative to "\033" # cf. http://en.wikipedia.org/wiki/ANSI_escape_code clear = "\e[0K" # reset lines reset = cr + clear #-------------------------------- Example 1 -------------------------------- (1..100).each do |i| print "#{reset}#{i}%" sleep(0.08) $stdout.flush end print "#{reset}" # clear current line $stdout.flush puts "done" #-------------------------------- Example 2 -------------------------------- chars = [ "|", "/", "-", "\\" ] # 7 turns on reverse video mode, 31 red , ... n = 31 str = "#{reset}\e[#{n};1m" (1..100).each do |i| case i when 0..10 then print "#{str}#{chars[0]}" when 10..20 then print "#{str}#{chars[1]}" when 20..30 then print "#{str}#{chars[2]}" when 30..40 then print "#{str}#{chars[3]}" when 40..50 then print "#{str}#{chars[0]}" when 50..60 then print "#{str}#{chars[1]}" when 60..70 then print "#{str}#{chars[2]}" when 70..80 then print "#{str}#{chars[3]}" when 80..90 then print "#{str}#{chars[0]}" when 90..100 then print "#{str}#{chars[1]}" end sleep(0.1) $stdout.flush end print "\e[0m" print "#{reset}" $stdout.flush puts "done" #-------------------------------- Example 3 -------------------------------- MAX = 80 $stdout.sync = true # alternative to $stdout.flush below 10.times do foo_string = Time.now.to_s s = foo_string[0..MAX].center(MAX) # or rjust or ljust print cr + s #$stdout.flush sleep(1.1) end print "\e[0m" print "#{reset}" $stdout.flush puts "done"
sqlite3 Pictures/Aperture\ Library.aplibrary/Aperture.aplib/Library.apdb vacuum