Skip to content

Instantly share code, notes, and snippets.

View dsshap's full-sized avatar

Dave Shapiro dsshap

View GitHub Profile
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

require 'rubygems'
require 'mechanize'
FIRST_NAME = 'FIRST_NAME'
LAST_NAME = 'LAST_NAME'
PHONE = 'PHONE'
EMAIL = 'EMAIL@provider.com'
PARTY_SIZE = 2
SCHEDULE_RANGE = { :start_time => '19:00', :end_time => '20:30' }
@krasnoukhov
krasnoukhov / 2013-01-07-profiling-memory-leaky-sidekiq-applications-with-ruby-2.1.md
Last active October 4, 2023 21: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"]
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@coopermaruyama
coopermaruyama / vendor-ffmpeg-heroku
Created October 27, 2012 08:39
Install FFMpeg on heroku (Rails)
## Get FFMpeg working on heroku by building binaries using vulcan
gem install vulcan
vulcan create foo
git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd ffmpeg
@chaslemley
chaslemley / dynamoDB_example.rb
Created January 23, 2012 15:17
Example of using Amazon's DynamoDB to store user activity
require "aws-sdk"
class Dynamo
attr_accessor :attributes
def initialize(hash)
raise ArgumentError, "argument passed to .new must be a Hash" unless hash.is_a? Hash
raise ArgumentError, "hash must contain key :#{self.class.hash_key}" unless hash.has_key? self.class.hash_key.to_sym
raise ArgumentError, "hash must contain key :#{self.class.range_key}" unless self.class.has_range_key? && hash.has_key?(self.class.range_key.to_sym)
@attributes = {}
@ewherrmann
ewherrmann / resque.rake
Last active July 2, 2020 00:36
Collection of Resque related custom rake tasks from around the web
require 'resque/tasks'
namespace :resque do
def del(key)
Resque.redis.keys(key).each { |k| Resque.redis.del(k) }
end
desc "Resque setup according to installation guide"
task :setup => :environment
@kenoir
kenoir / dynamo_db_query_example.md
Last active June 19, 2018 21:27
Prettied up some AWS Ruby SDK DynamoDB examples from @Integralist.

AWS query-instance_method docs

export AWS_ACCESS_KEY_ID=‘XXXX’
export AWS_SECRET_ACCESS_KEY=‘XXXX’
# ENV['AWS_ACCESS_KEY_ID']
# ENV['AWS_SECRET_ACCESS_KEY']
@elvanja
elvanja / deploy_discourse_to_heroku
Last active March 20, 2017 08:01
Helps deploy Discourse to Heroku with: * local asset precompiling * RedisCloud add-on * Autoscaler with Sidekiq add-on Details @ http://shcatula.wordpress.com/2013/07/08/deploying-discourse-to-heroku
#!/bin/sh
# http://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --; then
@noeticpenguin
noeticpenguin / rakefile.rb
Created June 10, 2013 15:12
Base Rakefile for RubyMotion projects incorporating the Salesforce Mobile SDK(iOS).
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/ios'
require 'rubygems'
require 'bundler'
Bundler.require
require 'sugarcube-repl'
Motion::Project::App.setup do |app|