Skip to content

Instantly share code, notes, and snippets.

View katafrakt's full-sized avatar
🐟

Paweł Świątkowski katafrakt

🐟
View GitHub Profile
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}"
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" ];
require 'hanami/validations'
class ReservationValidation
include Hanami::Validations
predicate :before? do |other, current|
current < other
end
validations do
@katafrakt
katafrakt / dynamic.rb
Created November 26, 2019 09:22
dynamic dry-v contract
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
@katafrakt
katafrakt / _test.rb
Created October 18, 2019 21:41
Shrine 3 entity problem
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')
}
@katafrakt
katafrakt / flash_test.rb
Created January 25, 2019 08:42
Problem with flash in Hanami
require 'bundler/inline'
gemfile do
gem 'hanami', '~> 1.3'
end
require 'hanami/action/session'
module Home
class Index
@katafrakt
katafrakt / 01_kraftwerk-example.rb
Last active January 5, 2019 18:08
This is a showcase for a new API framework under development. Code is not yet publicly available.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'kraftwerk', path: 'kraftwerk'
end
DATABASE = []
module Measures
@katafrakt
katafrakt / benchmark.rb
Created July 5, 2018 16:16
Object creation benchmark
require 'benchmark/ips'
class Service
def call(a, b)
a + b
end
end
Benchmark.ips do |x|
x.report("creation") do
@katafrakt
katafrakt / puma_rc.d.sh
Created October 11, 2012 18:59
simple and stupid Arch Linux rc.d script for starting and stopping puma (http://puma.io) with certain rails app
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
. /etc/profile
DAEMON=prozatorium
PIDFILE=/path/to/pidfile
app_path=/path/to/rails_app
config=config/puma.rb
046573a8640a2a13d7c1857678d5421ed619de1eb61ca8c48ee7ad379a0dfdc314882a0ab50207cf7643c7eaad6dba5292cbab90c1e4854b9eff60bbc56c4b7f62