This file contains hidden or 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
| Mix.install([:benchee]) | |
| defmodule Lookup do | |
| @lookup_table %{ | |
| "one" => :one, | |
| "two" => :two, | |
| "three" => :three | |
| } | |
| def by_table(value) do |
This file contains hidden or 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
| start_time = ~U[2025-05-23T09:21:17Z] | |
| s1 = session_fixture(started_at: start_time) | |
| s2 = session_fixture(started_at: DateTime.add(start_time, 60)) | |
| s3 = session_fixture(started_at: DateTime.add(start_time, 160)) | |
| s4 = | |
| session_fixture( | |
| started_at: DateTime.add(start_time, 245), | |
| finished_at: DateTime.add(start_time, 305) | |
| ) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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" ]; |
NewerOlder