Skip to content

Instantly share code, notes, and snippets.

View nathany's full-sized avatar
🙃

Nathan Youngman nathany

🙃
View GitHub Profile
@nathany
nathany / scope.go
Created July 27, 2012 19:17
Fiddling with scoping in Go
package main
import (
"fmt"
"log"
)
// Many functions in Go return an error as the last argument, nil for no error
func f() (int, error) {
return 42, nil
@nathany
nathany / LICENSE
Created January 21, 2012 07:19
Pruning remote branches that are already in master
Copyright (C) 2012 Nathan Youngman
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@nathany
nathany / decode_firmware_pwd.py
Created June 16, 2011 06:45
Decode Mac Open Firmware Password
# I forgot the firmware password on my MacBook Air and didn't want to take it in:
# http://support.apple.com/kb/TS2391
# info
# http://paulmakowski.blogspot.com/2009/03/apple-efi-firmware-passwords.html
# run the following command to retrieve your obfuscated firmware password:
# sudo nvram -p | grep security-password
security_password = "%..."
# take the complement of every second bit:
@nathany
nathany / git.rake
Created March 30, 2011 04:58
Generate a "Compare View" in markdown, complete with Gravatars and links to GitHub commits
require 'digest/md5'
namespace :git do
GITHUB_COMMIT_URL = "https://github.com/path/to/your/repo/commit/" # <= set me
# Before doing a deploy, I like to check GitHub's branch list
# but I wanted to be able to save it in a Lighthouse message
COMPARE_FOR = {
'production' => 'origin/production..origin/release',
@nathany
nathany / deploy.rb
Created March 7, 2011 03:51
Vagrant deploy.rb for Sprinkle using Capistrano delivery method
set :user, 'vagrant'
set :run_method, :sudo
role :app, '33.33.33.10'
ssh_options[:keys] = `vagrant ssh_config | grep IdentityFile`.split.last
@nathany
nathany / Vagrantfile
Created March 7, 2011 03:19
Vagrant Fabric experiment
Vagrant::Config.run do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "debian_squeeze_32"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://mathie-vagrant-boxes.s3.amazonaws.com/debian_squeeze_32.box"
# Assign this VM to a host only network IP, allowing you to access it via the IP.
config.vm.network "33.33.33.10"
@nathany
nathany / styleterm.scpt
Created December 15, 2010 20:12
Style your OS X terminal
-- osascript ~/styleterm.scpt 'Red Sands'
-- http://superuser.com/questions/187591/os-x-terminal-command-to-change-color-themes
on run argv
tell application "Terminal" to set current settings of selected tab of front window to first settings set whose name is (item 1 of argv)
end run
@nathany
nathany / fast_regex_list_split.cfm
Created December 15, 2010 16:54
Split a list into chunks, returns an array of lists
<cfscript>
function ListSplit(list, chunk_size, delim)
{
var result = ArrayNew(1); var re = ""; var start = 1;
while(1) {
re = REFind("((?:[^#delim#]+#delim#){1,#chunk_size#})", list & delim, start, "true");
if( re.len[1] eq 0 ) break;
ArrayAppend(result, Mid(list,re.pos[1],re.len[1]-len(delim)));
start = re.pos[1] + re.len[1];
if(start gte len(list)) break;
@nathany
nathany / assigned_to_sites.rb
Created December 3, 2010 18:19
Sometimes my Ruby code has enough parens, it might as well be Lisp
# find admin users assigned to a given set of sites
named_scope :assigned_to_sites, lambda { |site_ids|
{
:joins => :admin_user_site_assignments,
:conditions => {
:admin_user_site_assignments => {:site_id => site_ids}
}
}
}
@nathany
nathany / change_log.sql
Created October 27, 2010 21:37
Trigger to maintain a basic audit trail of changes to our Users table using PIVOTs instead of yucky, slow dynamic SQL.
-- Trigger to maintain a log of changes to the Users table (T-SQL, SQL Server 2005)
-- Presently only tracking UPDATEs
-- Inspiration from: http://goo.gl/Geds
IF OBJECT_ID('tr_ChangeLogOnUsers', 'TR') IS NOT NULL
DROP TRIGGER tr_ChangeLogOnUsers;
GO
CREATE TRIGGER tr_ChangeLogOnUsers ON Users FOR UPDATE
AS
-- only when LastModifiedBy is changed (someone made a change vs. something)