Skip to content

Instantly share code, notes, and snippets.

View bencrouse's full-sized avatar

Ben Crouse bencrouse

View GitHub Profile
@dennisfaust
dennisfaust / sidekiq_unique_jobs_hash_compactor.rb
Created July 12, 2017 20:46
sidekiq-unique-jobs gem not deleting expired keys in its uniquejobs hash
# https://github.com/mhenrixon/sidekiq-unique-jobs/issues/161
# Even worse: https://github.com/mhenrixon/sidekiq-unique-jobs/issues/234
class SidekiqUniqueJobsHashCompactor
include Sidekiq::Worker
sidekiq_options queue: "slow"
def perform
# Skip if there are jobs queued...
return unless Sidekiq::Queue.all.select { |q| q.size > 100 }.blank?
# Hook into unicorn, unicorn middleware, not rack middleware
#
# Since we need no knowledge about the request we can simply
# hook unicorn
module Middleware::UnicornOobgc
MIN_REQUESTS_PER_OOBGC = 5
MAX_DELTAS = 20
@jhjguxin
jhjguxin / first_vs_limit.markdown
Last active September 10, 2020 08:59
mongoid limit(1).first vs .first vs find_by performance?

.first vs .limit(1) performance?

Q:

Hi there, I noticed the following:

This query:

AvailabilityUpdate.where(hotel_id: "AT_INN_BINDERS").only(:timestamp).limit(1).entries.first.timestamp
@berryp
berryp / 04_jshint.rake
Created September 17, 2012 18:05 — forked from jamesarosen/04_jshint.rake
Javascript Loves CI: Jenkins + Jasmine + PhantomJS + JSHint
namespace :jshint do
task :require do
sh "which jshint" do |ok, res|
fail 'Cannot find jshint on $PATH' unless ok
end
end
task :check => 'jshint:require' do
project_root = File.expand_path('../../', File.dirname(__FILE__))
config_file = File.join(project_root, 'config', 'jshint.json')
@jdfdesign
jdfdesign / README.md
Created September 15, 2012 14:52 — forked from scottatron/README.md
Lossless compression of images in Rails using Dragonfly & image_optim

This runs provides an .optim job for dragonfly and also adds the .optim job into .thumb

This requires you have the 'image_optim' gem and it's dependencies.

@paulnicholson
paulnicholson / powssl
Last active November 24, 2021 16:40
ssl with pow using stud

Instructions

  • Install stud $ brew install https://raw.github.com/paulnicholson/homebrew/master/Library/Formula/stud.rb
  • Download and install the powssl script $ curl https://gist.githubusercontent.com/paulnicholson/2050941/raw/7e4d2178e3733bed18fdfe737277c3cb72241d39/powssl > ~/bin/powssl $ chmod +x ~/bin/powssl
  • Run powssl to create development certificate and configure stud.
  • $ powssl
# Rack middleware that drops non properly encoded cookies that would hurt the ActionDispatch::Cookies middleware.
#
# This is actually a hotfix for issues
# * https://github.com/rack/rack/issues/225
# * https://github.com/rails/rails/issues/2622
module CleanCookies
# Tests whether a string may be decoded as a form component
def decodable?(string)
URI.decode_www_form_component(string)
true
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
describe PostsController do
describe "GET index" do
subject { get :index }
it { should assign_to(:posts).with(Post.all) }
end
end