Skip to content

Instantly share code, notes, and snippets.

@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'
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"net/http"
"log"
"database/sql"
_ "github.com/lib/pq"
"encoding/json"
@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
@start = false
t1 = Thread.new do
while !@start
sleep 0.001
end
puts 'started 1'
end
N = 10_000
matched1 = 0
matched2 = 0
N.times do
seq = [1, 0, 0].shuffle
guess = rand(3)
matched1 += 1 if seq[guess].eql?(1)
@cutalion
cutalion / .rspec
Last active April 7, 2016 22:32
Arduino formatter for rspec
--color
--require spec_helper
--format Fuubar
--format ArduinoFormatter
Ничейщик = Class.new do
def self.name; "Ничейщик"; end
def self.inspect; "Ничейщик"; end
def self.Ничейщик; Ничейщик; end
def whoami?
self.class.name
end
@cutalion
cutalion / create_settings.rb
Last active November 18, 2015 09:04
Settings model for rails
class CreateSettings < ActiveRecord::Migration
def change
create_table :settings do |t|
t.string :key
t.string :human_name
t.text :value
t.timestamps null: false
end
end
end
class Array
undef :each
def each
return to_enum(__callee__) unless block_given?
size.times do |i|
yield self[i]
end
end
require 'rails_helper'
RSpec.describe UserReport do
# Jun | Aug | Sep
#-----|--|--|--|--|--|--|--> time
# * | * * |
#
# Short periods - weeks
# Stars - timelogs