Skip to content

Instantly share code, notes, and snippets.

John Nunemaker jnunemaker

Block or report user

Report or block jnunemaker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jnunemaker
jnunemaker / gist:87fb475129c0601fa72695afe912b02f
Created Sep 7, 2017
sha256 hexdigest to number for use in mapping a string to a partition number (not consistent hashing, but just in simple hash => partition)
View gist:87fb475129c0601fa72695afe912b02f
irb(main):001:0> require "digest"
=> true
irb(main):002:0> Digest::SHA256.hexdigest("asdf")
=> "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"
irb(main):003:0> Digest::SHA256.hexdigest("asdf").to_i(16)
=> 108959270400061671294053818573968651411470832267186275529291850190552309358907
irb(main):004:0> Digest::SHA256.hexdigest("asdf").to_i(16).to_s(16)
=> "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"
irb(main):005:0> Digest::SHA256.hexdigest("asdf").to_i(16) % 10
=> 7
View keybase.md

Keybase proof

I hereby claim:

  • I am jnunemaker on github.
  • I am jnunemaker (https://keybase.io/jnunemaker) on keybase.
  • I have a public key whose fingerprint is 2F06 D8EA 2B19 8EAB 40C2 7379 7BF1 39D1 EC76 CA82

To claim this, I am signing this object:

@jnunemaker
jnunemaker / mute_all_unread.js
Last active Feb 3, 2016
terrible github web notifications #protip: command + click any notifications you care about to open in new tab, then run the following in js console to mute the rest
View mute_all_unread.js
$('li.unread button.mute-note').each(function() { this.click() });
@jnunemaker
jnunemaker / catspam.sh
Created Apr 28, 2014
catspammer.com bash automation
View catspam.sh
catspam() {
curl -vvvv -d "{\"Body\":\"${1}\"}" -H "Content-Type: application/json" http://catspammer.com/api/cat
}
@jnunemaker
jnunemaker / wrists.md
Last active Aug 29, 2015
things that i've read, listened to, or tried in an effort to heal my hands/wrists/arms/shoulders
View wrists.md
@jnunemaker
jnunemaker / blocking_with_check.rb
Created Aug 9, 2013
Kestrel blocking client with signal checks for the kestrel-client gem.
View blocking_with_check.rb
module Kestrel
class Client
class BlockingWithCheck < Blocking
attr_accessor :return_check
def get(*args)
count = 0
while count += 1
@jnunemaker
jnunemaker / Gemfile
Created Mar 11, 2013
Eventually consistent alternate indexes using cassanity.
View Gemfile
source 'https://rubygems.org'
gem 'cassanity'
@jnunemaker
jnunemaker / db.rake
Created Mar 4, 2013
db.rake tasks for cassanity + migrations.
View db.rake
# ******************************************************************************
# 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 Dec 11, 2015
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.
View paginate_without_total.rb
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
You can’t perform that action at this time.