Skip to content

Instantly share code, notes, and snippets.

require "rspec/core"
module RSpec
class << Core::Runner
# SIGINT callback (installed by trap_interrupt)
undef handle_interrupt
def handle_interrupt
if RSpec.world.wants_to_quit
# The default way Ruby handles an interrupt signal.
# Makes current example fail with this exception as a cause.
@semaperepelitsa
semaperepelitsa / query.sql
Created July 11, 2019 21:48
ActiveJob "exponentially_longer" wait times
select n, delay, sum(delay) over (order by n) total_delay from (
select n, make_interval(secs => (pow(n, 4) + 2)::int) delay from generate_series(1, 20) n
) _;
@semaperepelitsa
semaperepelitsa / bench_set_types.sql
Last active May 19, 2021 13:48
Postgres: array vs hstore vs jsonb (set operations)
create extension if not exists hstore;
create table if not exists test_array as
select id, '{"A","B","C"}'::varchar[] || id::varchar as codes from generate_series(1, 100000) id;
create table if not exists test_hstore as
select id, '"A"=>t,"B"=>t,"C"=>t'::hstore || hstore(id::varchar, 't') as codes from generate_series(1, 100000) id;
create table if not exists test_jsonb as
select id, '{"A":true,"B":true,"C":true}'::jsonb || jsonb_build_object(id::varchar, true) as codes from generate_series(1, 100000) id;
\timing on
@semaperepelitsa
semaperepelitsa / benchmark.cljs
Created February 13, 2017 19:53
simple-benchmark clojurescript example
; Compare vector vs list:
cljs.user=> (simple-benchmark [nums (into (vector) (range 9999))] (nth nums 5000) 1000)
[nums (into (vector) (range 9999))], (nth nums 5000), 1000 runs, 2 msecs
nil
cljs.user=> (simple-benchmark [nums (into (list) (range 9999))] (nth nums 5000) 1000)
[nums (into (list) (range 9999))], (nth nums 5000), 1000 runs, 240 msecs
nil
; It looks similar to let:
@semaperepelitsa
semaperepelitsa / value_of.rb
Created July 7, 2015 23:41
Nokogiri node.value_of
gem "nokogiri", "~> 1.6.0"
require "nokogiri"
Nokogiri::XML::Searchable.module_eval do
def value_of(*args)
a = search(*args).first
a && a.content
end
alias :content_of :value_of
end
require "thread"
mutex = Mutex.new
i = 0
while true
i += 1
Thread.new(i) do |n|
mutex.synchronize do
puts "#{n}. started request"
@semaperepelitsa
semaperepelitsa / Isolate
Last active August 29, 2015 13:56
Rake warnings (using Isolate)
options system: false, cleanup: false
@semaperepelitsa
semaperepelitsa / functional_test.rb
Created October 24, 2013 13:25
Functional test for subdomain locale engine
# encoding: UTF-8
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
class HelloControllerTest < ActionController::TestCase
def test_links
@request.host = "example.com"
@semaperepelitsa
semaperepelitsa / dragonfly_test.rb
Created July 17, 2013 20:54
Testing Fog over HTTP Proxy
gem "dragonfly", "~> 0.9.14"
require "dragonfly"
img = Dragonfly[:images]
img.datastore = Dragonfly::DataStorage::S3DataStore.new(
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket_name: ENV['S3_BUCKET_NAME']
)
@semaperepelitsa
semaperepelitsa / steam.txt
Created July 17, 2013 11:33
My computer's specs
Processor Information:
Model: MacBookAir4,2
Vendor: GenuineIntel
Speed: 1800 Mhz
4 logical processors
2 physical processors
HyperThreading: Supported
FCMOV: Supported
SSE2: Supported
SSE3: Supported