Skip to content

Instantly share code, notes, and snippets.

View JamesMcMahon's full-sized avatar

James F McMahon JamesMcMahon

View GitHub Profile
@JamesMcMahon
JamesMcMahon / fib.clj
Last active November 8, 2015 01:11
Fibonacci generator in Clojure. Playing with memoization.
; Need to forward declare this symbol to use it in fib
(declare memo-fib)
(defn fib
"Returns the fibonacci number for the given position."
[n]
(if (or 0 1)
n
(+' (memo-fib (-' n 1)) (memo-fib (-' n 2)))))
@JamesMcMahon
JamesMcMahon / pivotal_story_summary.rb
Last active August 29, 2015 14:14
Pivotal story summarizer (to save me some time on Sundays)
#!/usr/bin/env ruby
# encoding: utf-8
##
# Markdown summarizer for Pivotal stories
#
# Usage './pivotal_story_summary.rb <project-id> <username>'
#
#
# The MIT License (MIT)
@JamesMcMahon
JamesMcMahon / stupid-fib.py
Last active August 29, 2015 14:03
Some days you just can't write a fibonacci generator, today is not that day
#!/usr/bin/env python
# -*- coding: utf-8 -*-
cache = {0: 0, 1: 1}
def fib(n):
if n in cache:
return cache[n]
f = fib(n - 1) + fib(n - 2)
@JamesMcMahon
JamesMcMahon / ec2-autoscale-instances.py
Created March 20, 2014 20:34
Script to dynamically grab public DNS names from an EC2 autoscale instances
#!/usr/bin/env python
"""
ec2-autoscale-instance.py
Read Autoscale DNS from AWS
Sample config file,
{
"access_key": "key",
#!/usr/bin/env ruby
# encoding: utf-8
# converted from http://stackoverflow.com/a/19801386/20774
# Much more efficent then my initial pass
require 'set'
def palindromes(input)
result = Set.new
input.size.times do |i|
@JamesMcMahon
JamesMcMahon / backup-tm-rsync.sh
Last active January 2, 2016 15:29
Timemachine style backup through rsync
#!/usr/bin/env bash
date=`date "+%Y-%m-%dT%H_%M_%S"`
backup_home=/mnt/storage/rsync-backup
rsync -azxqP \
--delete \
--link-dest=$backup_home/current \
--exclude='.gvfs' \
--delete-excluded \
#!/usr/bin/python
'''
Copyright 2009, The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
import skillz.*
import skillz.admin.*
def quartzScheduler = ctx.getBean('quartzScheduler')
quartzScheduler.start()
GameMetricsJob.triggerNow()
@JamesMcMahon
JamesMcMahon / bcrypt-cli.rb
Last active December 17, 2015 09:19
Ruby Command Line Bcrypt
#!/usr/bin/env ruby
require 'bcrypt'
print BCrypt::Password.create ARGV.shift
@JamesMcMahon
JamesMcMahon / decorate.py
Created July 28, 2012 18:58
Decorate Python Test
# level one
def foo(fn):
def inner():
return 'foo' + fn()
return inner
@foo
def bar():
return 'bar'
# level two