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
defmodule IexHelpers do | |
def search_fn(name) do | |
:code.all_loaded() | |
|> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end) | |
|> Enum.map(fn {mod, _} -> mod end) | |
|> Enum.each(fn mod -> | |
mod.__info__(:functions) | |
|> Enum.each(fn {fun_name, arity} -> | |
if fun_name == name do | |
IO.puts "#{mod}.#{fun_name}/#{arity}" |
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 'hanami/validations' | |
class ReservationValidation | |
include Hanami::Validations | |
predicate :before? do |other, current| | |
current < other | |
end | |
validations do |
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 'dry/validation' | |
# fake dynamic fields | |
dynamic_fields = ->() { %i[email name] } | |
contract = Class.new(Dry::Validation::Contract) do | |
params do | |
dynamic_fields.().each do |f| | |
required(f).filled(:string) | |
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 'shrine' | |
require 'shrine/storage/file_system' | |
require 'image_processing/mini_magick' | |
Dir.mktmpdir do |tmp| | |
Shrine.storages = { | |
cache: Shrine::Storage::FileSystem.new(tmp), | |
store: Shrine::Storage::FileSystem.new(tmp, prefix: 'uploads') | |
} |
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 'bundler/inline' | |
gemfile do | |
gem 'hanami', '~> 1.3' | |
end | |
require 'hanami/action/session' | |
module Home | |
class Index |
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 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'kraftwerk', path: 'kraftwerk' | |
end | |
DATABASE = [] | |
module Measures |
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/ips' | |
class Service | |
def call(a, b) | |
a + b | |
end | |
end | |
Benchmark.ips do |x| | |
x.report("creation") do |
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
digraph finite_state_machine { | |
rankdir=LR; | |
size="8,5" | |
labelloc = "t"; | |
label = "/a/"; | |
"" [shape = none]; | |
node [shape = doublecircle]; q1; | |
node [shape = circle]; | |
"" -> q0; | |
q0 -> q1 [ label = "a" ]; |
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
046573a8640a2a13d7c1857678d5421ed619de1eb61ca8c48ee7ad379a0dfdc314882a0ab50207cf7643c7eaad6dba5292cbab90c1e4854b9eff60bbc56c4b7f62 |
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 Program < Hash | |
Recv = Class.new(StandardError) | |
attr_reader :last_sound | |
def set(reg, val) | |
self[reg] = value(val) | |
end | |
def add(reg, val) | |
self[reg] += value(val) |
NewerOlder