Skip to content

Instantly share code, notes, and snippets.

MonitorOutdatedGems::Config.new do
set_frequency_default "monthly"
set_versions_default "MAJOR"
monitor "strong_migrations", versions: "PATCH"
monitor "browser", versions: "MINOR"
monitor "annotate", versions: "MAJOR"
end

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"]
@dlynam
dlynam / redis.markdown
Created February 3, 2016 22:13 — forked from bdotdub/redis.markdown
Running redis using upstart on Ubuntu

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

@dlynam
dlynam / deploy.rb
Created January 27, 2016 22:16 — forked from mitio/deploy.rb
Sidekiq + Capistrano + Ubuntu Upstart
# config/deploy.rb
namespace :upstart do
desc 'Generate and upload Upstard configs for daemons needed by the app'
task :update_configs, except: {no_release: true} do
upstart_config_files = File.expand_path('../upstart/*.conf.erb', __FILE__)
upstart_root = '/etc/init'
Dir[upstart_config_files].each do |upstart_config_file|
config = ERB.new(IO.read(upstart_config_file)).result(binding)
class TicTacToe
attr_accessor :board, :winner
attr_reader :winning_positions
def initialize
@board = create_board
@winner = nil
@winning_positions = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9], [1, 5, 9], [3, 5, 7] ]
end
@dlynam
dlynam / gist:88b9bddfab3e845cdd90
Last active August 29, 2015 14:04
Code Sample (Product model, like model, and product liker service object)
class Product < ActiveRecord::Base
scope :approved, -> { where(:approved => true) }
serialize :large_dimensions
belongs_to :submitter, class_name: 'User', foreign_key: 'user_id'
has_many :likes, as: :likeable, dependent: :destroy
<!--
The purpose of the following is to provide a callback to the parent window
so we can transfer the data retrieved from Gmail omnicontacts
-->
<%= hidden_field_tag 'contacts_callback', @contacts.to_json, id: "contacts_callback" %>
<% content_for :scripts do %>
<script>
// Set a Global variable to be accessed by the parent window
#!/usr/bin/env ruby
require 'open-uri'
require 'JSON'
require 'digest/sha2'
require 'pry'
require 'bigdecimal'
require 'bitcoin' # Because I need to cheat every now and then
# Usage:
# gem install pry json ffi ruby-bitcoin
<% content_for :head do %>
<% end %>
<% if flash[:notice] %>
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<%= flash[:notice] %>
</div>
<% end %>
#route
resources :users do
get :activate, on: :member
end
#view
<%= form_for @user, :url => activate_user_path(@user) do |f| %>
....
<% end %>