Skip to content

Instantly share code, notes, and snippets.

View Erol's full-sized avatar

Erol Fornoles Erol

  • Laguna, Philippines
View GitHub Profile
class TestWorker < ApplicationWorker
sidekiq_options retry: false, queue: 'test'
def perform
Sidekiq::Batch.new.tap do |batch|
batch.on(:death, 'TestWorker#on_death')
batch.jobs do
SampleWorker.perform_async
end
end
@Erol
Erol / Query Log
Last active September 25, 2020 06:07
Query Log
{
"query": {
"find": "items",
"filter": {
"parent_id": {
"$oid": "..."
},
"$or": [
{
"title": {
@Erol
Erol / benchmark.rb
Last active January 11, 2017 11:10
Ethos Benchmark Comparison
require 'benchmark/ips'
require 'fast_attributes'
require 'virtus'
require 'attrio'
require 'anima'
require 'ethos/entity'
ATTR_NAMES = [:attr0, :attr1, :attr2, :attr3, :attr4, :attr5, :attr6, :attr7, :attr8, :attr9]
class FastIntegers
@Erol
Erol / benchmark.rb
Last active August 29, 2015 14:12
Kernel#load vs Kernel#eval
require 'benchmark'
Benchmark.bmbm do |bm|
bm.report '1000 x Kernel#load wrap=false' do
1000.times do
load 'script.rb', false
end
end
bm.report '1000 x Kernel#load wrap=true' do
@Erol
Erol / example.rb
Created July 11, 2013 01:22
Make selecting or rejecting items from an Ohm collection faster by getting only selected fields.
require 'benchmark'
User.all.size
#=> 30000
# BEFORE
Benchmark.measure { User.all.select { |user| user.firstname =~ /Erol/ } }
#=> 66.630000 1.070000 67.700000 ( 67.868905)
# AFTER
@Erol
Erol / benchmark.rb
Last active December 18, 2015 22:49
Benchmark: Select from an Ohm Model's All Set vs Arrays Directly Returned by Redis
require 'benchmark'
User.all.size #=> 30000
Benchmark.bm(30) do |bm|
bm.report 'User Instances' do
User.all
.select { |user| user.lastname.downcase == 'erol' }
end
@Erol
Erol / benchmark.rb
Last active December 17, 2015 13:38
Benchmark: String Interpolation vs Concatenation
require 'benchmark'
n = 100_000
Benchmark.bm(10) do |bm|
bm.report('interpolation') { n.times { "#{ 1 }/#{ 2 }" } }
bm.report('concatenation') { n.times { 1.to_s + '/' + 2.to_s } }
end
@Erol
Erol / benchmark.rb
Last active December 17, 2015 13:38
Benchmark: String#+ vs String#<<
require 'benchmark'
s = ""
t = ""
n = 100_000
Benchmark.bm(10) do |bm|
bm.report('String#+') { n.times { s += "A" } }
bm.report('String#<<') { n.times { t << "A" } }
@Erol
Erol / benchmark.rb
Last active December 17, 2015 13:29
Benchmark: Tap vs Non-Tap
require 'benchmark'
def tap_method
result = rand.tap {}
end
def non_tap_method
result = rand
result
end
@Erol
Erol / nginx.conf
Created March 4, 2013 16:20
iOS 6 Fix: Globally set Cache-Control no-cache on POST requests
http {
if ($request_method = 'POST') {
add_header 'Cache-Control' 'no-cache';
}
}