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 'strscan' | |
class Result | |
class Ok < self | |
def or(&block) | |
self | |
end | |
def and(&block) | |
chained = block.call(value) |
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 | |
require 'bundler/setup' | |
require 'parser/current' | |
require 'pry' | |
def each_file | |
return to_enum(:each_file) unless block_given? | |
Dir['app/**/*.rb'].sort.each { |f| yield f } |
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
# frozen_string_literal: true | |
# Cache store that gets automatically expired after each request | |
# | |
# @example | |
# UsersCache = RequestStore::Cache.new(namespace: 'users') | |
# UsersCache.read(:user1) | |
# # => nil | |
# UsersCache.fetch(:user1) { User.find(1) } | |
# # => #<User id:1 ...> |
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
./configure | |
alias dev-ruby-rebuild="make DESTDIR=./ruby_build uninstall && make && make DESTDIR=./ruby_build install" | |
alias dev-ruby="./ruby_build/usr/local/bin/ruby -I ./ruby_build/usr/local/lib/ruby/2.5.0 -I ./ruby_build/usr/local/lib/ruby/2.5.0/x86_64-darwin17" | |
alias dev-irb="dev-ruby -e 'binding.irb'" |
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 'parslet' | |
require 'json' | |
class JSONParser < Parslet::Parser | |
rule(:object) { str('{') >> spaces? >> object_content.maybe.as(:object) >> spaces? >> str('}') } | |
rule(:object_content) { (kv_pair >> (comma >> kv_pair).repeat).maybe } | |
rule(:kv_pair) { (key.as(:key) >> spaces? >> str(':') >> spaces? >> value.as(:value)).as(:kv_pair) } | |
rule(:key) { string } | |
rule(:value) { string | float | integer | object | array | _true | _false | null } | |
rule(:string) { str('"') >> (str('"').absent? >> any).repeat.as(:string) >> str('"') } |
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
# racc json_parser.rb -o out.rb -v -g && ruby -rpry -rstrscan out.rb | |
class JsonParser | |
token tDOT tQUOTE | |
tLCURLY tRCURLY | |
tLBRACK tRBRACK | |
tCOMMA tCOLON | |
tSTRING tNUMBER | |
kTRUE kFALSE kNULL | |
rule |
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
# gem install activesupport | |
# runner.rb | sh | |
require 'active_support/values/time_zone' | |
ActiveSupport::TimeZone::MAPPING.values.each do |zone| | |
puts "TZ=#{zone} opal -e 'print \"#{zone}: \"; puts Time.at(9999999).yday'" | |
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
apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A | |
echo "deb http://repo.percona.com/apt trusty main" > /etc/apt/sources.list.d/percona.list | |
echo "deb-src http://repo.percona.com/apt trusty main" >> /etc/apt/sources.list.d/percona.list | |
apt-get update | |
apt-get install -y percona-server-server-5.6 | |
mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'" | |
mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'" | |
mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'" |
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
config.sync = | |
# ... | |
couchDB: | |
urlRoot: 'http://localhost:5984' | |
options: | |
dataType: 'json' | |
contentType: 'application/json; charset=UTF-8' |
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 ComparesByValue | |
def <=>(other) | |
self.value <=> other.value | |
end | |
end | |
class A < Struct.new(:value) | |
include ComparesByValue | |
include Comparable | |
end |
NewerOlder