Skip to content

Instantly share code, notes, and snippets.

View andrhamm's full-sized avatar
:shipit:
Shipping 🔥 & ⚡️

Andrew Hammond andrhamm

:shipit:
Shipping 🔥 & ⚡️
View GitHub Profile
@andrhamm
andrhamm / redis-expireeq.rb
Last active August 29, 2015 14:27
Redis LUA script for atomically setting a key's expiration if its value is unchanged
# EXPIREEQ key value_assertion seconds
# Set a timeout on key if the current value equals value_assertion.
# EXPIREEQ is short for "EXPIRE if EQual"
# The lua script:
expireeq = <<-EOF
local key = KEYS[1]
local val_assert = ARGV[1]
local ex = ARGV[2]
local val = redis.call("GET", key)
@andrhamm
andrhamm / update-github-diffstats.js
Created January 27, 2013 17:44
Wanted to take a screenshot of GitHub diff-stats UI but didn't want to count some of the files/changes in the commit so I wrote a quick script to update them after deleting unwanted nodes from the DOM.
/*
* Use Chrome web inspector to remove elements for files
* you don't want to count in the diff stats, then run this
* function to update the diff stats in the UI
*/
function () {
var allAdditions = 0;
$(".diffstat > a").each( function (index, element) {
$(".diffstat-bar", this).remove();
var addition = $.trim($(this).text().replace(/[A-Za-z$-]/g, ""));