Skip to content

Instantly share code, notes, and snippets.

@start = false
t1 = Thread.new do
while !@start
sleep 0.001
end
puts 'started 1'
end
@cutalion
cutalion / curry.rb
Last active November 22, 2016 09:46
class SuperCurry
def call(a, b)
puts "#{a} + #{b} = #{a + b}"
end
def curry(*args)
arity = method(:call).arity
curried_args = args
if curried_args.size == arity
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"net/http"
"log"
"database/sql"
_ "github.com/lib/pq"
"encoding/json"
@cutalion
cutalion / Gemfile
Last active September 14, 2017 15:28
ROM issue with polymorphic association and aggregation
source "https://rubygems.org"
gem 'sqlite3'
gem 'dry-logic', github: 'dry-rb/dry-logic', branch: 'master'
gem 'dry-types', github: 'dry-rb/dry-types', branch: 'master'
gem 'rom', github: 'rom-rb/rom', branch: 'master'
gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
gem 'pry'
require 'rom'
require 'rom-repository'
require 'rom-sql'
require 'pry'
module Entity
end
config = ROM::Configuration.new(:sql, 'sqlite::memory')
conn = config.gateways[:default].connection

Keybase proof

I hereby claim:

  • I am cutalion on github.
  • I am cutalion (https://keybase.io/cutalion) on keybase.
  • I have a public key ASA_TnJvySK6SN95G7RdeuuJi2XAcunV37SabTXa2IwBcAo

To claim this, I am signing this object:

@cutalion
cutalion / Gemfile
Last active March 5, 2018 17:03
ROM sql-memory combine
source "https://rubygems.org"
gem 'sqlite3'
gem 'dry-logic'
gem 'dry-types'
gem 'rom'
gem 'rom-sql'
gem 'pry'
# Пусть админы могут удалять комментарии
# и мы уведомляем кого-нибудь, что комментарий был удален
class DeleteComment
def call(comment)
transaction do
comment.delete!
user.decrement(:comments_count)
end
module Initializer
def initialize
puts 'Initializer#initialize'
super
end
end
class Klass
prepend Initializer
@cutalion
cutalion / exceptions.rb
Last active February 7, 2020 12:48
monads vs exceptions
require 'pry'
# A
# |- B
# | |- D
# |
# |- C
AppError = Class.new(StandardError)
Error1 = Class.new(AppError)