Skip to content

Instantly share code, notes, and snippets.

View aaronchi's full-sized avatar

Aaron Eisenberger aaronchi

  • Santa Monica, CA
View GitHub Profile
@wagenet
wagenet / application_policy.rb
Created May 6, 2021 21:25
Graphiti + Pundit
# frozen_string_literal: true
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
@krasnoukhov
krasnoukhov / 2013-01-07-profiling-memory-leaky-sidekiq-applications-with-ruby-2.1.md
Last active September 28, 2025 09:53
Profiling memory leaky Sidekiq applications with Ruby 2.1

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration:

if ENV["PROFILE"]
@stuartbain
stuartbain / subdomain_validator.rb
Last active October 25, 2021 22:33
Custom validator for Subdomains
class SubdomainValidator < ActiveModel::EachValidator
# http://matthewhutchinson.net/2010/10/27/rails-3-subdomain-validation-activemodeleachvalidator
def validate_each(object, attribute, value)
return unless value.present?
reserved_names = %w(www ftp mail pop smtp admin ssl sftp)
reserved_names = options[:reserved] if options[:reserved]
if reserved_names.include?(value)
object.errors[attribute] << 'cannot be a reserved name'
end
@akonan
akonan / Gemfile
Created May 29, 2011 11:47
Steps to get Google OpenID working with Devise and Omniauth
# Add this line to your Gemfile
gem "oa-openid", :require => "omniauth/openid"