This file contains hidden or 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 'strscan' | |
s = StringScanner.new("1{2{3}; 1{2} }") | |
stack = [[]] | |
until s.eos? | |
if s.scan(/\{/) | |
stack << [] | |
elsif s.scan(/\}/) |
This file contains hidden or 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 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? |
This file contains hidden or 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
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 |
This file contains hidden or 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
test = Hash.new | |
test.class == Hash #=> true | |
case test.class.to_s | |
when "Hash" | |
true | |
else | |
false | |
end | |
end #=> true |
This file contains hidden or 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 '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 |
This file contains hidden or 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 higher_order | |
lambda{|arg| arg + yield(5) } | |
end | |
foo = lambda{|arg| arg + 1 } | |
higher_order(&foo).(3) # => 9 |
This file contains hidden or 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 '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 |
This file contains hidden or 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/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 |
This file contains hidden or 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 File | |
def tail(n) | |
buffer = 1024 | |
idx = (size - buffer).abs | |
chunks = [] | |
lines = 0 | |
begin | |
seek(idx) | |
chunk = read(buffer) |
This file contains hidden or 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
>> 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 |