Skip to content

Instantly share code, notes, and snippets.

View thisivan's full-sized avatar

Ivan Torres thisivan

View GitHub Profile
@thisivan
thisivan / replace_text_in_files_with_sed.sh
Created January 19, 2010 19:04
Replace Text in Files with Sed
# Replace text in files using regular expressions:
find db/migrate -type f -name "*" -exec sed -i -e "s/:precision => 2, :scale => 14/:precision => 14, :scale => 2/g" "{}" \;
# Find replacements made:
grep ":precision => 2, :scale => 14" db/migrate/. -R

Time.strftime

%a - The abbreviated weekday name (``Sun'')
%A - The  full  weekday  name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The  full  month  name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
# Replace text in files using regular expressions
# test your search
find . | xargs grep ':precision => 2, :scale => 14' -l
# replace text
find db/migrate -type f -name "*" -exec sed -i -e "s/:precision => 2, :scale => 14/:precision => 14, :scale => 2/g" "{}" \;
# test your results
grep ":precision => 2, :scale => 14" db/migrate/. -R
# Rebase
$ git commit -a -m "Commit message"
$ git fetch
$ git rebase [branch] # origin/master
$ git push
# Stash
$ git stash
$ git pull
$ git stash apply
" Change leader key from \ to ,
let mapleader = ","
map <leader>s :TlistToggle<CR>
map <leader>f :FuzzyFinderTextMate<CR>
map <leader>l :BufExplorer<CR>
map <leader>t :NERDTreeToggle<CR>
map <leader>w :b#<CR>
onAdd : function () {
this.getPanes().floatPane.appendChild(this.element.get(0));
},
#!/bin/sh
### BEGIN INIT INFO
# Provides: god
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: God
### END INIT INFO
# Hex digest a file, without loading the whole file into memory:
require 'digest/md5'
def md5sum_file(path)
digest = Digest::MD5.new
File.open(path, 'r') do |file|
while buffer = file.read(1024*8)
digest << buffer
end
begin
open(params[:tracking_lead_uri])
rescue OpenURI::HTTPError
puts "Couldn't make your request."
end
// make sure curl is installed
if (function_exists('curl_init')) {
// initialize a new curl resource
$ch = curl_init();
// set the url to fetch
curl_setopt($ch, CURLOPT_URL, $_GET['tracking_lead_uri']);
}