Skip to content

Instantly share code, notes, and snippets.

# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {
#!/bin/bash
wget https://credis.googlecode.com/files/credis-0.2.3.tar.gz
tar -zxvf credis-0.2.3.tar.gz
cd credis-0.2.3
make

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"]
$ dig app5.zeropush.com @ns1.dreamhost.com ANY
;; Truncated, retrying in TCP mode.
; <<>> DiG 9.8.3-P1 <<>> app5.zeropush.com @ns1.dreamhost.com ANY
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62516
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
/*
Copyright (c) 2010 Adam Duke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
/* Forces exclusive access to a database allowing a restore and subsequently restores the database from a backup file. This will interrupt any existing connections and rollback any in progress transactions. Use at your own risk. */
ALTER DATABASE [database_name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [database_name]
FROM DISK = N'C:\path\to\backup\backupfile.bak'
WITH FILE = 1, KEEP_REPLICATION, NOUNLOAD, REPLACE, STATS = 10
GO
@adamvduke
adamvduke / gist:749493
Created December 21, 2010 04:34
Inline edits text files to add a newline between the start of a control block i.e. method declaration, if/else statement etc... and opening curly brace.
#gsed is the GNU version of sed
#OSX ships with the BSD version which is apparently not the same
gsed -i 's/\([[:space:]]*\)\([[:print:]]\{1,\}\){/\1\2\n\1{/' ./Classes/*.m
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class Dependencies {
Map <String, Collection <String>> dependencyMap = new HashMap <String, Collection <String>>();
@adamvduke
adamvduke / AnalyticsRBelongToUs.php
Created February 24, 2011 16:41
A php file to register views in google analytics
<?php
$var_utmac='UA-XXXXX'; //enter the new urchin code
$var_utmhn='ihazdomain.com'; //enter your domain
$var_utmcs='UTF-8'; // character set?
$var_utmsr='800x600'; //screen resolution
$var_utmsc='24-bit'; // screen colors
$var_utmul='en-us'; // language
$var_utmn=rand(1000000000,9999999999);//random request number
$var_cookie=rand(10000000,99999999);//random cookie number
$var_random=rand(1000000000,2147483647); //number under 2147483647
#!/usr/bin/env ruby
# Seems a bit silly to have a script to run redcloth considering you can just run
# $ redcloth inputfile.textile > outputfile.html
# but whatever
class Textilize
require 'rubygems'
require 'redcloth'