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 ActiveSupport | |
# A typical module looks like this: | |
# | |
# module M | |
# def self.included(base) | |
# base.extend ClassMethods | |
# base.class_eval do | |
# scope :disabled, -> { where(disabled: true) } | |
# 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 "pp" | |
MAPPING = { | |
1 => [], | |
2 => %w(A B C), | |
3 => %w(D E F), | |
4 => %w(G H I), | |
5 => %w(J K L), | |
6 => %w(M N O), | |
7 => %w(P Q R S), |
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 "json" | |
class JsonSlop | |
def initialize(json) | |
@hash = json.is_a?(String) ? JSON.parse(json) : json | |
end | |
def call | |
JsonSlopProxy.new(@hash) | |
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
import java.lang.reflect.Method; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.HashMap; | |
/** | |
* We wrote DynamicMethodCall as a helper class to allow writing wrapper | |
* classes in Java by passing methods as data to call later. | |
* It allows you to call methods on an object where the method name is passed | |
* as a String. This is useful for simplifying anonymous method usage like GUI | |
* event handler, for example. It is capable of calling inherited methods, |
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 DynamicIvars | |
def greet(**options) | |
options.each { |k, v| instance_variable_set :"@#{k}", v } | |
p @hello | |
end | |
end | |
DynamicIvars.new.greet hello: "world" | |
# => "world" |
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
# Classic Ackermann explosively exponential function | |
# some attempt at optimization though better optimizations are known | |
import sys | |
from sys import setrecursionlimit | |
sys.setrecursionlimit(50000) | |
depthM = 5 | |
depthN = 1 | |
answers = [] |
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 reverse_color; "\033[7m#{self}\033[27m" end | |
end | |
class Cell | |
attr_accessor :alive | |
def initialize(neighbors) | |
@neighbors = neighbors | |
@alive = @fate = [false, true].sample |
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
crystal run test.cr | |
#=> "foo" | |
crystal build test.cr | |
export CRYSTAL_PATH=/usr/local/Cellar/crystal/0.7.1/src | |
./test | |
#=> | |
ld: library not found for -levent | |
clang: error: linker command failed with exit code 1 (use -v to see invocation) |
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
# Comment the below compile_options out and | |
# this will crash with stack level too deep. | |
# Based on http://timelessrepo.com/tailin-ruby | |
RubyVM::InstructionSequence.compile_option = { | |
tailcall_optimization: true, | |
trace_instruction: false | |
} | |
RubyVM::InstructionSequence.new(<<-CODE).eval |
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
group :test do | |
gem 'minitest-reporters' | |
gem 'rb-blink1' | |
end |