Skip to content

Instantly share code, notes, and snippets.

@alloy-d
alloy-d / gitconfig
Last active December 21, 2015 12:59
Git configuration
[user]
name = Adam Lloyd
email = adam@alloy-d.net
[alias]
ci = commit
co = checkout
d = difftool
st = status --short
current = rev-parse --abbrev-ref HEAD
autocommit = !"git commit -m \"$(curl -s 'http://whatthecommit.com' | grep -A1 'id=\"content\"' | tail -n 1 | tr -d '<p>')\""
# It is acknowledged that all perl one-liners here are both inelegant
# and probably great targets for replacement with sed.
# Get a list of fully merged branches:
git branch --merged | perl -pe '$_ =~ s/..//' > branches
# edit branches to exclude branches that shouldn't be deleted (example: master)
module Kernel
alias_method :_orig_raise, :raise
def raise(*args)
begin
_orig_raise(*args)
rescue Exception => e
Bugsnag.notify(e)
_orig_raise(e)
end
end
@alloy-d
alloy-d / logger.js
Created February 4, 2013 22:23
IE MAKES LOGGING IN JAVASCRIPT SO FUN.
define(function () {
var exports = {};
funcs = ["log", "warn", "error", "group", "groupEnd"];
for (var i in funcs) {
exports[funcs[i]] = (function (func) {
return function () {
if (typeof(console) !== "undefined" && funcs[i] in console) {
console[func].apply(console, arguments);
}
};
@alloy-d
alloy-d / awareness-utils.rb
Created December 3, 2012 19:23
Fun with Ruby Procs and the stack.
module AwarenessUtils
# Example: `define_method :current_method_name, StackWalker.new(2)`
class StackWalker < Proc
def self.new(depth=1)
super() { instance_eval { caller[depth] =~ /`(.+)'/ and $1 } }
end
end
end
@alloy-d
alloy-d / options_with_indifferent_access.rb
Created October 25, 2012 23:14
Awful Ruby hack for forcing the last argument (generally an options hash) to all of a class's methods to be a HashWithIndifferentAccess.
module OptionsWithIndifferentAccess
module ClassMethods
def method_added(method_name)
unless caller[1].match(/`method_added'/)
define_method("_orig_#{method_name}".intern, instance_method(method_name))
define_method(method_name) do |*args, &block|
if args[-1].is_a? Hash
args[-1] = HashWithIndifferentAccess.new(args[-1])
end
self.send "_orig_#{method_name}", *args, &block
@alloy-d
alloy-d / questions.json
Created October 2, 2012 17:03
JSON representing comment fields for a blog on which identity is a name and a spirit animal.
[
{
"name": "commenter[name]", // the name attribute; should also be used to create the id
"text": "Your name (pseudonyms are okay)", // the text of an associated label
"required": true, // this field should not be left blank
}, // => A basic text field
{
"name": "commenter[email]",
"text": "Your email address (will not be shown)",
"type": "email", // this field represents an email address
@alloy-d
alloy-d / beginning-of-day.js
Created September 19, 2012 17:38
Given a JS date object, get an ISO 8601 string for the beginning of that day in a target timezone.
var beginningOfDayWithOffset = function (targetOffset) {
var pad = function (n) { return (n.toString().length === 2 ? n.toString() : "0" + n) }
var sign = "-";
var offsetHours, offsetMinutes, offsetString;
// That's right, JavaScript's timezone offset has the opposite sign of the
// offset in ISO 8601...
if (targetOffset <= 0) {
sign = "+";
@alloy-d
alloy-d / callback-example.js
Created September 8, 2012 22:17
Ridiculous callback example
// We're coding an awesome website.
//
// For a great user experience, we want to add a personalized greeting.
// Here is a function that gives said personalized greeting, given the user's name.
function greetUserLikeIts1995(firstName) {
alert("Hello there, " + firstName + "!");
}
// For security, we use carrier pigeons to get information from our users.
// Unfortunately, it's a slow process, so we don't want to just sit around
@alloy-d
alloy-d / Default.sublime-commands
Created July 15, 2012 21:53
Simple Sublime Text 2 plugin to enable quick toggling of the 'draw_white_space' setting between 'selection' and 'all'.
[
{"caption": "Toggle Shown Spaces", "command": "toggle_shown_spaces"}
]