Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
jnunemaker / wrists.md
Last active August 29, 2015 13:56
things that i've read, listened to, or tried in an effort to heal my hands/wrists/arms/shoulders
@jnunemaker
jnunemaker / blocking_with_check.rb
Created August 9, 2013 19:25
Kestrel blocking client with signal checks for the kestrel-client gem.
module Kestrel
class Client
class BlockingWithCheck < Blocking
attr_accessor :return_check
def get(*args)
count = 0
while count += 1
@jnunemaker
jnunemaker / Gemfile
Created March 11, 2013 17:07
Eventually consistent alternate indexes using cassanity.
source 'https://rubygems.org'
gem 'cassanity'
@jnunemaker
jnunemaker / db.rake
Created March 4, 2013 21:58
db.rake tasks for cassanity + migrations.
# ******************************************************************************
# NOTE: You will need to replace keyspace and migrations_path in the rake tasks
# below with whatever makes sense for your application. You will also need a
# task named environment that loads whatever is need to make cassanity available.
# ******************************************************************************
namespace :db do
desc "Run any pending migrations."
task :migrate => :environment do
require 'cassanity/migrator'
@jnunemaker
jnunemaker / paginate_without_total.rb
Last active December 11, 2015 03:59
Paginate without the count for plucky. Probably doesn't work with will paginate, but if you just have previous / next it works great and avoids expensive count calls.
Plucky::Query.class_eval do
def paginate_without_total(opts={})
page = (opts.delete(:page) || 1).to_i
limit = (opts.delete(:per_page) || per_page).to_i
skip = (page - 1) * limit
all(opts.merge(:limit => limit, :skip => skip))
end
end
@jnunemaker
jnunemaker / gist:4495290
Created January 9, 2013 18:00
Web And Mobile Revenue Models
@jnunemaker
jnunemaker / gist:3093898
Created July 11, 2012 21:58
RubyConf Brazil Talk

Addicted to Stable

Stable? In most developer communities, especially Ruby, stable seems nothing short of a curse word. Everyone seems to be addicted to new. I should know, as I once was. Heck, I even own addictedtonew.com.

Over the past few years, my sentiments have changed. Through my experience maintaining and growing a handful of applications, I have grown to respect and love stability.

This talk is jam packed with everything I have learned about building and growing a production application. Stories of mistakes and victories will abound.

@jnunemaker
jnunemaker / mongodb_slave_synced_time.rb
Created June 12, 2012 02:24
mogodb get last synced time for slave in master/slave setup
db.command(BSON::OrderedHash['serverStatus', 1, 'repl', 1])['repl']['sources'].first['syncedTo']['time']
@jnunemaker
jnunemaker / mind_blower_ruby19.rb
Created May 30, 2012 13:40
Mongo allows objects as _id. _id is always indexed and Mongo knows how to index complex objects.
require 'pp'
require 'rubygems'
require 'mongo'
conn = Mongo::Connection.new
db = conn.db('test')
col = db['test']
col.remove
oid = BSON::ObjectId.new