This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use this script to find local git repos where you have something uncommitted. | |
The script searches your hard-drive for repos using the unix "locate" command. To check which directories locate might skip see /etc/updatedb.conf | |
PRUNEPATHS variable lists directories which are skipped, so remove folders to include them in search. | |
For more info, run "man locate" and "man updatedb" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# - Place this snippet in you .bashrc or .bash_profile (if you're on a Mac) | |
# to make bash history much more useful. | |
# - This basically shares bash history between multiple shell instances and makes the history available everywehere. | |
# - If your using CTRL-R bash shortcut, this is triples your bash productivity. | |
#merge history | |
export HISTCONTROL=erasedups # no duplicate entries | |
export HISTFILESIZE=10000000 # big big history | |
export HISTSIZE=1000000 # big big history | |
# Save and reload the history after each command finishes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_chars(str) | |
str.split("").inject(0) do |s, c| | |
s + c[0] | |
end | |
end | |
a = ["hello", "i", "am", "blah"] | |
sum = (0...(a.size)).inject(0) do |s, i| | |
s + sum_chars(a[i])*i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'algorithms' | |
def most_common_5(str) #O(n + klog(n)) | |
tally = {} # to count the number of occurences | |
word = Struct.new(:word, :frequency) #little helper struct | |
splitter = /[ \*:,\.!\?\n]+/ #to separate words in paragraphs | |
str.split(splitter).each do |term| #O(n) | |
tally[term] ||= 0 #initialize to 1 if first found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Character make1(byte b1) | |
Character make2(byte b1, byte b2) | |
//helper routine tests if a byte starts with 1-bit | |
boolean testFor1(byte b) { | |
if (b & 0b10000000) { | |
return true; | |
} else { | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#case 1 | |
a = 3 | |
def foo(z) | |
z = 5 | |
end | |
def baz(z) | |
z += 1 | |
end | |
foo(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#environment.rb | |
require 'active_record' | |
require 'sqlite3' | |
require 'logger' | |
ActiveRecord::Base.configurations = YAML::load(IO.read('config/database.yml')) | |
ActiveRecord::Base.establish_connection('development') | |
ActiveRecord::Base.logger = Logger.new('log/debug.log') | |
development: | |
adapter: sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dir | |
def self.current | |
Dir.new(Dir.pwd) | |
end | |
def children | |
p = path | |
entries.reject{|f| f =~ /^\..*/ }.map do |name| | |
child_path = p + "/" + name | |
if File.directory? child_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pstore' | |
class KVS | |
def self.open(path) | |
KVS.new(path) | |
end | |
def initialize(path) | |
@pstore = PStore.new path | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 | |
94.94, -28.18 | |
76.47, -113.90 | |
-120.14, -181.20 | |
-115.41, 93.00 | |
-35.11, 59.41 | |
36.24, -179.82 | |
-111.93, 8.18 | |
-127.18, -80.15 | |
80.93, 117.31 |
OlderNewer