Skip to content

Instantly share code, notes, and snippets.

@manveru
manveru / stack.rb
Created September 28, 2010 11:02
Simple StringScanner solution for parsing nested braces
require 'strscan'
s = StringScanner.new("1{2{3}; 1{2} }")
stack = [[]]
until s.eos?
if s.scan(/\{/)
stack << []
elsif s.scan(/\}/)
module ProjectReader
module_function
# finds keys in .erb files from a given directory
def find_keys(path)
keys = Dir[File.join(path, '**/*.erb')].map{|path|
extract_keys(path)
}.flatten
unless keys.empty?
diff --git a/lib/rack/sendfile.rb b/lib/rack/sendfile.rb
index 177f452..19cfd74 100644
--- a/lib/rack/sendfile.rb
+++ b/lib/rack/sendfile.rb
@@ -47,8 +47,8 @@ module Rack
# }
#
# Note that the X-Sendfile-Type header must be set exactly as shown above. The
- # X-Accel-Mapping header should specify the name of the private URL pattern,
- # followed by an equals sign (=), followed by the location on the file system
@manveru
manveru / gist:591771
Created September 22, 2010 14:31 — forked from simi/gist:591759
test = Hash.new
test.class == Hash #=> true
case test.class.to_s
when "Hash"
true
else
false
end
end #=> true
require 'readline'
require 'set'
word = File.readlines('/usr/share/dict/words').sample
letters = word.downcase.chars.to_a
seen = Hash[letters.zip(Array.new(letters.size, false))]
guessed = Set.new
lives = 6
@manveru
manveru / higher.rb
Created September 22, 2010 08:56 — forked from hackervera/higher.rb
def higher_order
lambda{|arg| arg + yield(5) }
end
foo = lambda{|arg| arg + 1 }
higher_order(&foo).(3) # => 9
require 'benchmark'
class Numeric
def split_digits_1(base = 10)
# head, last = self.divmod(base)
head = self / base
last = self % base
head < base ? [head, last] : head.split_digits_1(base).push(last)
end
#!/usr/bin/ruby
$stdout.sync = true
while now = Time.now
# now = Time.at 60 * 30
print "De tijd is nu: #{now.strftime("%H:%M:%S")}"
if now.min + now.sec == 0
print " ", "." * now.hour
class File
def tail(n)
buffer = 1024
idx = (size - buffer).abs
chunks = []
lines = 0
begin
seek(idx)
chunk = read(buffer)
>> puts lambda{ a = [*1..100] }.block.method.decode
0000: push_cpath_top
0001: find_const 0
0003: meta_push_1
0004: push_int 100
0006: send_stack :new, 2
0009: cast_array
0010: set_local 0
0012: ret
=> nil