Skip to content

Instantly share code, notes, and snippets.

@alobato
alobato / scp
Created May 13, 2010 00:25
Copy directory from remote server using SCP
# Copy directory from remote server using SCP
scp -r username@host:/var/www .
#!/usr/bin/env ruby
# Raffle script. Uses Quicksilver (http://docs.blacktree.com/quicksilver/what_is_quicksilver) and Applescript
# CSV file of attendees was downloaded from EventWax (http://www.eventwax.com/). It needs 2 returns to continue the raffle
# - one to bring focus back to the terminal.
require 'rubygems'
require 'appscript'
require 'yaml'
require 'fastercsv'
@alobato
alobato / file_examples.rb
Created May 17, 2010 12:41
__FILE__ examples
puts __FILE__
puts File.dirname(__FILE__)
puts File.expand_path(__FILE__)
puts File.expand_path(File.dirname(__FILE__))
# Search and Replace in all files within a directory recursively on Linux
# http://www.jonasblog.com/2006/05/search-and-replace-in-all-files-within-a-directory-recursively.html
find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;
# Extracting HTML/XML tag text data using sed
# http://alleightllc.wordpress.com/2007/12/13/extracting-htmlxml-tag-text-data-using-sed/
sed -n -e 's/.*<id>\(.*\)<\/id>.*/\1/p' file.xml
# Só Sed
# http://thobias.org/doc/sosed.html
# Sharing a git repo on the network
# http://paulbarry.com/articles/2010/02/06/sharing-a-git-repo-on-the-network
git daemon --base-path=/path/to/dir/with/repo --export-all
@alobato
alobato / console_url_for.rb
Created May 19, 2010 12:55
Using url_for and expire_page in console and runner
# Using url_for and expire_page in console and runner
# http://pjkh.com/articles/2007/12/12/using-url_for-and-expire_page-in-console-and-runner
app.url_for(:controller => 'foo', :action => 'bar')
app.url_for(:controller => 'foo', :action => 'bar')
# => 'http://www.example.com/foo/bar'
app.url_for(:controller => 'foo', :action => 'bar', :only_path => true)
# => '/foo/bar'
app.host! 'www.mydomain.com'
# => 'www.mydomain.com'
# One-liner to install nginx with passenger and ssl
# http://pragmatig.com/2010/05/22/one-liner-to-install-nginx-with-passenger-and-ssl/
wget -O /tmp/nginx-0.7.64.tar.gz http://sysoev.ru/nginx/nginx-0.7.64.tar.gz && cd /tmp && tar xzvf nginx-0.7.64.tar.gz && sudo passenger-install-nginx-module --nginx-source-dir /tmp/nginx-0.7.64 --extra-configure-flags="--with-http_ssl_module" --auto --prefix=/opt/nginx-0.7.64 && sudo ln -s /opt/nginx-0.7.64 /opt/nginx
# imprime somente as linhas que se encaixam na expressão regular
# (emula o "grep")
sed '/regexp/!d'
# procura e imprime por AAA e BBB e CCC (em qualquer ordem)
sed '/AAA/!d; /BBB/!d; /CCC/!d'
# imprime somente as linhas com menos que 65 caracteres
sed '/^.\{65\}/d'