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 Table | |
# 1 is an identity, so we know it's composition with other elements. | |
ELTS = [1, :a, :b].freeze | |
BASIC = {'11' => 1, '1a' => :a, '1b' => :b, 'a1' => :a, 'b1' => :b}.freeze | |
# Iterate through all possible composition tables. | |
def self.each | |
return to_enum unless block_given? | |
ELTS.product(ELTS, ELTS, ELTS) { |list| yield new(*list) } |
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 Where | |
class <<self | |
attr_accessor :editor | |
def is_proc(proc) | |
source_location(proc) | |
end | |
def is_method(klass, method_name) | |
source_location(klass.method(method_name)) |
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
[alias] | |
s = !git status | |
k = !gitk | |
br = !git branch | |
co = "!f() { git checkout `git locax $1`; }; f" | |
ff = !git reset --hard origin/`git this` | |
ffm = !git push . origin/master:master | |
new = !git checkout -b | |
brd = "!f() { git branch -D `git loca $1`; }; f" | |
grab = !git fetch origin -p |
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 Hash | |
def using(&block) | |
values = block.parameters.map do |(type, name)| | |
self[name] | |
end | |
block.call(*values) | |
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 'benchmark' | |
require 'date' | |
# from lib/core_ext/hash.rb | |
class Hash | |
def at(*path) | |
path.inject(self) do |ob, key| | |
ob.respond_to?(:each) ? ob[key] : nil | |
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
STOP den lille kænguru | |
Tre fra Litauen på indbrud | |
Gemte sig bag ved en hæk | |
Tævede gamle fru Jensen | |
Tog pengene med og var væk! | |
Men så råbte vi: | |
Stop de østkriminelle | |
Før de røver igen |
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 Databound | |
class Manager | |
def find_scoped_records(only_extra_scopes: false) | |
if only_extra_scopes | |
rel = model.where(@scope.to_h) | |
else | |
rel = model.where(params.to_h) | |
check_permit!(:read, rel) # <<< this is out of place, because SRP! | |
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
# a monkey-patch fix for OR-query building, needed for Rails 4.2 | |
module Databound | |
class Manager | |
def or_query(root, *scopes) | |
relations = scopes.map do |scope| | |
root.where(scope.to_h) | |
end | |
nodes = relations.map do |rel| | |
rel.where_values.reduce(:and) |
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 Array | |
def deep_compact | |
term = [] | |
hash = each_with_object({}) do |obj,res| | |
if obj.is_a?(Hash) | |
obj.each do |key,val| | |
res[key] ||= [] | |
res[key] += val.respond_to?(:deep_compact) ? val.deep_compact : val | |
end | |
else |
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 A | |
def method_missing(_, value, *_) | |
puts "A: #{value.inspect} #{_.inspect}" | |
end | |
def existing1(_, value, *_) | |
puts "Ae1: #{value.inspect} #{_.inspect}" | |
end | |
def existing2(_, value, *) | |
puts "Ae2: #{value.inspect} #{_.inspect}" | |
end |
NewerOlder