Skip to content

Instantly share code, notes, and snippets.

View thisivan's full-sized avatar

Ivan Torres thisivan

View GitHub Profile
# 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
#!/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
onAdd : function () {
this.getPanes().floatPane.appendChild(this.element.get(0));
},
" 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>
# Rebase
$ git commit -a -m "Commit message"
$ git fetch
$ git rebase [branch] # origin/master
$ git push
# Stash
$ git stash
$ git pull
$ git stash apply
# 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

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)
@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
@thisivan
thisivan / javascript_prototype_singleton_objects.js
Created January 19, 2010 18:55
Creating Singleton objects with JavaScript
// Defining constructor function
function SingletonObject() {
// TODO: Add your own initialization code here
this._message = 'Hello Prototype World!';
};
// Current instance property
SingletonObject._instance = null;
SingletonObject.getInstance = function() {
@thisivan
thisivan / javascript_prototype_objects.js
Created January 19, 2010 18:41
Creating Prototype objects with JavaScript
// Defining constructor function
function ObjectConstructor(message) {
// TODO: Add your own initialization code here
this.message = message || 'Hello Prototype World!';
};
// Defining an instance function
ObjectConstructor.prototype.sayHello = function() {
alert(this.message);
};