Skip to content

Instantly share code, notes, and snippets.

@dschneider
dschneider / make_s3_dump.sh
Created October 25, 2013 13:56
Make a dump from redis and put it on S3
/opt/redis/bin/redis-cli save
sudo s3cmd put /redis/dump.rdb s3://elastic-cache-snapshots
echo "I AM AMAZING"
@dschneider
dschneider / ruby_magic.rb
Created October 25, 2013 11:44
Mindblowing Ruby magic
tail -f /var/log/app/current |grep ip-11-26-26-121|grep total=|ruby -ane 'p $F.grep(/total/)'
@dschneider
dschneider / sed_replace.sh
Last active December 25, 2015 21:09
Replace value in file with SED
sudo sed -n -i 's/pool\: [0-9]/pool\: '$SIZE'/g' /opt/app/config/database.yml
@dschneider
dschneider / package_installed.sh
Created October 16, 2013 08:44
Determine whether a package is installed or not in a shell script
if dpkg-query -W mysql-client &> /dev/null; then
echo "INSTALLED"
else
echo "NOT INSTALLED"
fi
@dschneider
dschneider / ProviderCallbackApp.rb
Created October 3, 2013 14:17
A small Sinatra app that can be used to catch a service provider callback (e. g. from Facebook, Twitter or Google) using OmniAuth.
require 'sinatra'
require 'omniauth'
# A small Sinatra app that can be used to catch a service provider
# callback (e. g. from Facebook, Twitter or Google) using OmniAuth.
# It can be mounted in the routes. This Sinatra app can be useful
# if you have a Rails API app without any cookies / sessions.
#
# Examples
#
@dschneider
dschneider / Install VIM with X Window support
Created May 12, 2013 11:18
I prefer to use VIM with the system clipboard instead of the regular yank register. Most often this is not enabled on X based systems - here is how to compile it with X support.
# Check for xterm_clipboard support
vim --version
# Get the compile-dependencies of vim
sudo apt-get build-dep vim
# If you haven't got mercurial, get it
sudo apt-get install mercurial
# Get the source
@dschneider
dschneider / rbtrace.txt
Created November 29, 2012 08:00
rbtrace
Redis::Client#process
Redis::Client#logging
Redis::Client#ensure_connected
Redis::Client#connected?
Redis::Connection::Ruby#connected? <0.000003>
Redis::Client#connected? <0.000010>
Process.pid <0.000004>
Array#each
Array#first <0.000003>
Redis::Client#write
@dschneider
dschneider / Gemfile.lock
Created November 29, 2012 07:56
My Gemfile.lock
GIT
remote: git://github.com/softa/activerecord-postgres-hstore.git
revision: a211841295882aa3e2c267750037b8bc58da5546
ref: a211841295882aa3e2c267750037b8bc58da5546
specs:
activerecord-postgres-hstore (0.4.0)
pg
rails
rake
@dschneider
dschneider / BCryptOptimisation.rb
Created November 25, 2012 18:04
BCrypt optimisation for use in testing.
require 'bcrypt'
silence_warnings do
BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
end
@dschneider
dschneider / DeferredGarbageCollection.rb
Created November 25, 2012 17:55
Deferred Garbage Collection for speeding up unit and integration tests
# Public: This class contains methods for deferred garbage collection which
# improves the time consumption of integration and unit tests.
class DeferredGarbageCollection
# Public: The time threshold used by the deferred garbage collection. It's
# either set as an environment variable or defaults to 5 seconds.
GC_THRESHOLD = (ENV['DEFER_GC'] || 5.0).to_f
# Public: The last time the GC has run.
@@last_gc_run = Time.now