Skip to content

Instantly share code, notes, and snippets.

View JamesMcMahon's full-sized avatar

James F McMahon JamesMcMahon

  • VMWare
  • Chicago, IL
View GitHub Profile
@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 / 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)
#!/bin/bash
set -o errexit
# Author: David Underhill
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
if [ $# -eq 0 ]; then
exit 0
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
#!/usr/bin/env bash
git filter-branch --index-filter 'git rm --cached --ignore-unmatch '$1'' --prune-empty --tag-name-filter cat -- --all
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
require 'sinatra'
require 'json'
get '/hi' do
"Hello World!"
end
get '/json' do
content_type :json
{ :key1 => 'value1', :key2 => 'value2' }.to_json
@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
@JamesMcMahon
JamesMcMahon / max.hs
Created November 8, 2015 00:36
Haskell lazy performance test
#!/usr/bin/env runhaskell
maximum' :: (Ord a) => [a] -> a
maximum' [] = error "maximum of empty list"
maximum' [x] = x
maximum' (x:xs) = max x (maximum' xs)
main :: IO ()
main = do
-- print (maximum' [3, 5, 7, 3, 6])
@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)))))
#!/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|