Skip to content

Instantly share code, notes, and snippets.

View nathany's full-sized avatar
🙃

Nathan Youngman nathany

🙃
View GitHub Profile
@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 / 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)
@nathany
nathany / config.ru
Last active May 3, 2019 17:10
Magical Unicorn Configuration for Heroku
# add something like this to config.ru
# see https://github.com/kzk/unicorn-worker-killer
if Integer(ENV['UNICORN_KILLER'] || 0) != 0
require 'unicorn/worker_killer'
# Max memory size (RSS) per worker
use Unicorn::WorkerKiller::Oom, (350*(1024**2)), (400*(1024**2)), 30, true
end
@nathany
nathany / gist:190489
Created September 21, 2009 19:20
index-of-any, based on Stuart Halloway's Programming Clojure book, but with attempts in Python and Ruby (of course regex would be another, string-only, option)
// Returns the index of the first character contained in searchChars
// From Apache Commons Lang, http://commons.apache.org/lang/
public static int indexOfAny(String str, char[] searchChars) {
if (isEmpty(str) || ArrayUtils.isEmpty(searchChars)) {
return -1;
}
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
for (int j = 0; j < searchChars.length; j++) {
if (searchChars[j] == ch) {

Keybase proof

I hereby claim:

  • I am nathany on github.
  • I am nathany (https://keybase.io/nathany) on keybase.
  • I have a public key ASDQMnXaH02CR8BQhuy4A0xJpt8RfQDOIkGAJFX9QuNlIAo

To claim this, I am signing this object:

@nathany
nathany / luhn.ex
Last active December 28, 2016 08:10
Luhn algorithm to checksum credit cards.
defmodule Luhn do
@moduledoc """
Luhn algorithm to checksum credit cards.
"""
@doc """
Check if a credit card number is valid based on luhn.
"""
def valid?(cc) when is_integer(cc) do
Integer.digits(cc)
* mixins (include and extend) for simple modularization (vs. multiple inheritance or traits in other languages)
* innovations in the web space (haml, rack middleware, etc.)
* standardized around MIT and GIT
* no public properties (attr_accessor, etc.)
* open classes
* tooling (gem, rake)
* animal references (ducks, monkeys, bacon)
* metaprogramming (unicorns)
* TDD/BDD emphasis and tools
@nathany
nathany / checksum.go
Created August 11, 2016 23:09
Using MultiWriter to do two things at once
// copyAndChecksum calculates a checksum while writing to another output
func copyAndChecksum(w io.Writer, r io.Reader) (string, error) {
h := md5.New()
mw := io.MultiWriter(w, h)
if _, err := io.Copy(mw, r); err != nil {
return "", err
}
return hex.EncodeToString(h.Sum(nil)), nil
}
@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;
package main
import (
"os"
"testing"
)
func TestGetSHA(t *testing.T) {
sha, err := getSHA1()
if err != nil {