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
#!/usr/bin/env ruby | |
$count = 0 | |
def out *args | |
# During resizing events, terminals may not do a carriage return | |
# on their own, so we have to explicitly insert it | |
print "#{args.join ' '}\r\n" | |
end | |
command = lambda { |x| |
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
1.9.3> require 'bson' | |
=> true | |
1.9.3> require 'json' | |
=> true | |
1.9.3> require 'yaml' | |
=> true | |
1.9.3> h = {foo: 'bar'} | |
=> {:foo=>"bar"} | |
1.9.3> b = BSON.serialize h | |
=> foobar |
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 LogReader | |
def self.open filename | |
new File.open filename, 'r' | |
end | |
def initialize file | |
raise ArgumentError, 'File required!' unless File === file | |
@file = file | |
end | |
attr :file |
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
files = Hash.new Array.new | |
file = Pathname.new '../.DS_Store' | |
hash = Digest::SHA256.file file | |
# This results in weirdness | |
files[hash.to_s] << file | |
files #=> {} | |
files.length #=> 0 | |
file[hash.to_s] #=> [#<Pathname:../.DS_Store>] |
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
## Single pass | |
$ time bin/rivalry .. | |
-- Size : 299 MB | |
-- Count : 1456 files | |
-- Dupes : 301 files | |
real 0m2.604s | |
user 0m2.435s | |
sys 0m0.163s |
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
module ConfigModule | |
def [] key | |
config.send key | |
end | |
def config | |
@config ||= load_config | |
end | |
def config_file file |
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
LazyStruct.new({:a=>1, :b => 2}).a # => 2 | |
# That's wrong. Why? |
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
#99 x 99 = 9312 | | |
def reset | |
"\e[0m" | |
end | |
def mult l, r | |
lb = 10 ** l.to_s.size | |
rb = 10 ** r.to_s.size |
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
Ideal Specs | |
CPU: 3.7Ghz QuadCore 3rd Gen i7 | |
Mem: 16GB @ 1600MHz | |
GPU: NVIDIA GeForce GTX 680MX | |
HDD: 750GB SSD | |
Wifi: 802.11N | |
Screen: 13"/14" 1600x900 | |
Bluetooth: Yes |
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
#!/usr/bin/env ruby | |
# Translates a text file to Pig Latin! | |
class PigLatin | |
def initialize filename = nil | |
@filename = filename | |
end | |
attr :filename | |
def translate! |