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 that_method(parameter) | |
array_list = ['Thing', 'Another Thing'] | |
array_list.include? parameter | |
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
require "openssl" | |
require 'digest/sha2' | |
require 'securerandom' | |
# Automatically upgradable encryption provider | |
module Encryption | |
class InvalidData < StandardError | |
end | |
class InvalidPattern < InvalidData | |
def initialize(version) |
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
### The stuff to encrypt | |
data = 'hello world!' | |
password = 'test123' | |
# Note: all 3 implementations are supposed to do exactly the same | |
### Raw OpenSSL | |
# Decisions, decisions, decisions... | |
cipher = 'AES-256-CBC' # which ciphers are not trivially broken? |
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 Jacob | |
class Model | |
class ColumnDsl | |
# [snip] | |
def integer(name, null: false, default: nil, size: nil, primary_key: false, auto_increment: false, unique: false) | |
# [snip] | |
end | |
# [snip] |
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 Unreachable < StandardError | |
end | |
module Kernel | |
module_function def unreachable(msg="This place in the code should never have been reached") | |
raise Unreachable, msg | |
end | |
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
require 'webrick' | |
include WEBrick | |
s = HTTPServer.new( | |
:Port => 9951, | |
:DocumentRoot => File.expand_path(File.dirname(__FILE__)) | |
) | |
s.config[:MimeTypes].update({ | |
"text" => "text/plain", | |
}) | |
trap("INT") { s.stop } |
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
pg.exec_params("CREATE TABLE foos (data bytea)") | |
para = Array.new(256).pack("C*") # => "\x00\x01\x02\x03\x04\x05…\xFE\xFF" | |
pg.exec_params("INSERT INTO foos ($1)", [para]) | |
pg.exec_params("SELECT * FROM foos").to_a # => [{"data"=>"\\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
module Lib | |
def has_color | |
define_method(:color) do 'red' end | |
end | |
end | |
class Car | |
extend Lib | |
has_color | |
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
class String | |
def segments | |
segments = split(/\./) | |
while segments.size > 1 | |
yield(segments.join('.')) | |
segments.pop | |
end | |
yield('.') | |
end | |
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
#!/usr/bin/env ruby | |
# hackery to simulate a file | |
require 'stringio' | |
RealFile = File | |
Object.send(:remove_const, :File) | |
File = StringIO | |
def StringIO.open(data); x=new(data);x.rewind; x; end | |
# end of hackery | |