Skip to content

Instantly share code, notes, and snippets.

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
@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
path = require 'path'
webpack = require 'webpack'
exec = require 'exec-sync'
gemDir = (name) ->
exec('bundle show ' + name)
refileDir = path.join(gemDir('refile'), 'app/assets/javascripts')
jqueryRailsDir = path.join(gemDir('jquery-rails'), 'vendor/assets/javascripts')
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
@cutalion
cutalion / README.md
Last active December 24, 2015 07:19
Make all files in S3 "directory" private or public

Once I've got a task to make a lot of files stored on S3 private. In my project I used carrierwave and fog.
All files were public by default.

In order not to make many requests to AWS, I've decided to change bucket policy instead of ACL of each file.

@cutalion
cutalion / README.md
Last active December 23, 2015 23:59
Temporary turn VCR off

I often use VCR gem. And I always configure it to use rspec metadata to turn it on with just :vcr symbol.

When I know that some module will always hit the external service, I turn VCR on at the very top describe.

describe "Something", :vcr do
  it "should make coffee" do
  end