See demo
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 'cgi' | |
require 'json' | |
require 'active_support' | |
def verify_and_decrypt_session_cookie(cookie, secret_key_base) | |
cookie = CGI::unescape(cookie) | |
salt = 'encrypted cookie' | |
signed_salt = 'signed encrypted cookie' | |
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000) | |
secret = key_generator.generate_key(salt) |
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 'socket' | |
class Client | |
def initialize server, socket | |
@server, @socket = server, socket | |
start | |
end | |
def send message | |
@socket.puts message |
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 Interactor | |
attr_reader :error | |
def self.perform(*args) | |
new(*args).tap { |interactor| catch(:fail) { interactor.perform } } | |
end | |
def success? | |
@error.nil? | |
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
# conversation: https://github.com/rack/rack/commit/734a00c5f4bb46e9a5e6e2677d89a2f285dcc185 | |
# | |
# user system total real | |
# reverse: 0.010000 0.010000 0.020000 ( 0.024657) | |
# join: 0.050000 0.010000 0.060000 ( 0.056571) | |
# regexp: 0.050000 0.000000 0.050000 ( 0.048339) | |
require 'benchmark' | |
def join(session_data) |
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
#!/bin/sh | |
# $ dasherize Hello, world! I am tonytonyjan. | |
printf "$*" \ | |
| tr '[:upper:]' '[:lower:]' \ | |
| tr -C '[:alnum:]' ' ' \ | |
| tr -s ' ' '-' \ | |
| sed -e 's/^-*//' -e 's/-*$//' \ | |
| tr -d '\n' |
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 'benchmark' | |
n = 100000000 | |
Benchmark.bmbm do |x| | |
x.report('[4, 5].max') { n.times { [4, 5].max } } | |
a, b = 4, 5 | |
x.report('[a, b].max') { n.times { [a, b].max } } | |
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
module AutoLoader | |
def self.included(mod) | |
caller_path, = caller(1..1).first.partition(':') | |
pattern = "#{File.dirname(caller_path)}/#{File.basename(caller_path, '.rb')}/*.rb" | |
Dir.glob(pattern).each do |path| | |
class_name = ::Utils.classify(File.basename(path, '.rb')).to_sym | |
mod.autoload class_name, path | |
end | |
end | |
end |
I hereby claim:
- I am tonytonyjan on github.
- I am tonytonyjan (https://keybase.io/tonytonyjan) on keybase.
- I have a public key whose fingerprint is EF91 623D 1477 800D 5701 24B6 294A EB9F 5C88 9A31
To claim this, I am signing this object: