Skip to content

Instantly share code, notes, and snippets.

View mattdodge's full-sized avatar
😺
Oh look! A status that I'll never change again!

Matt Dodge mattdodge

😺
Oh look! A status that I'll never change again!
View GitHub Profile
@mattdodge
mattdodge / gist:90704ecbbfecc78be50f
Created March 2, 2015 19:57
Human Readable Time Difference
function timeAgo(num_seconds) {
function numberEnding (number) {
return (number > 1) ? 's ago' : ' ago';
}
if (num_seconds <= 0) {
return 'just now!';
}
var years = Math.floor(num_seconds / 31536000);
if (years) {
return years + ' yr' + numberEnding(years);
@mattdodge
mattdodge / php_file_editor.php
Created June 20, 2012 19:19
Simple PHP File Editor
<?php
$the_file = "file.txt";
if (isset($_POST['content'])) {
$content = stripslashes($_POST['content']);
$fp = fopen($the_file,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
}
@mattdodge
mattdodge / bracketBayes.py
Created March 19, 2013 16:50
Run a Bayesian analysis on matchup probabilities for an NCAA bracket. This will spit out the probability that each seed makes it to a given round
'''
Created on Mar 18, 2013
@author: Matt Dodge
'''
'''
You can put your own probabilities here. It is a dict where the key is the lower seed
(lower by number, not by rank) followed by the higher seed, separated by comma, no space.
@mattdodge
mattdodge / ncaaMatchupProbability.py
Created March 19, 2013 17:52
A utility that hits TeamRankings and gets the matchup probabilities for each team in the NCAA tournament. You will need to hard-code (blech) all of the team IDs for now, I'm lazy
'''
Created on Mar 18, 2013
@author: Matt Dodge
'''
from bs4 import BeautifulSoup as BS
from httplib2 import Http
from urllib import urlencode
import json
@mattdodge
mattdodge / solve24.py
Created July 19, 2013 23:18
Solve the game 24 for any solution target and any numbers n = The target number (e.g. 24) nums = Array of numbers (floating point ok) to use solveStr = A helper string for this recursive method that returns a formula This method will return the first (not exhaustive!) possible solution to the game, or False if none exists Example: For the 24 gam…
def solve(n, nums, solveStr='x'):
''' Solve the game 24 for any solution target and any numbers
n = The target number (e.g. 24)
nums = Array of numbers (floating point ok) to use
solveStr = A helper string for this recursive method that returns a formula
This method will return the first (not exhaustive!) possible solution to the game, or False if none exists
Example: For the 24 game 1,3,4,6 call it the following way:
solve(24, [1,3,4,6])
@mattdodge
mattdodge / solve24.py
Last active December 20, 2015 00:39
Trimmed down 24 solver
def solve(n, nums, solveStr='x'):
''' Play 24 with nums 1,3,4,6 like so:
>>> solve(24, [1,3,4,6])
(6/(1-(3/4))) '''
n = float(n)
solved = False
if len(nums) == 1:
return (solveStr.replace('x', str(int(n))) if n == float(nums[0]) else False)

Keybase proof

I hereby claim:

  • I am mattdodge on github.
  • I am mattdodge (https://keybase.io/mattdodge) on keybase.
  • I have a public key whose fingerprint is 4E10 1C96 3077 8865 8293 3F28 9947 BDF9 6192 D7D9

To claim this, I am signing this object:

@mattdodge
mattdodge / kiper_mcshay.md
Created May 19, 2017 01:07
Mel Kiper vs Todd McShay 2013 Draft
Pick Team McShay Kiper Actual
1 Kansas City Eric Fisher (OT - Central Michigan) Eric Fisher (OT - Central Michigan) Eric Fisher (OT - Central Michigan)
2 Jacksonville Dion Jordan (DE - Oregon) Luke Joeckel (OT - Texas A&M) Luke Joeckel (OT - Texas A&M)
3 Oakland Sharrif Floyd (DT - Florida) Sharrif Floyd (DT - Florida) Dion Jordan (DE - Oregon)
4 Philadelphia Lane Johnson (OT - Oklahoma) Lane Johnson (OT - Oklahoma) Lane Johnson (OT - Oklahoma)
5 Detroit Ezekiel Ansah (DE - BYU) Ezekiel Ansah (DE - BYU) Ezekiel Ansah (DE - BYU)
6 Cleveland Geno Smith (QB - WVU) Dee Milliner (CB - Alabama) Barkevious Mingo (DE - LSU)
7 Arizona Jonathan Cooper (G - UNC) Dion Jordan (DE - Oregon) Jonathan Cooper (G - UNC)
8 Buffalo Ryan Nassib (QB - Syracuse) Jonathan Cooper (G - UNC) Tavon Austin (WR - WVU)
@mattdodge
mattdodge / headless.sh
Created January 10, 2018 21:45
Make existing kubernetes services headless
kubectl get svc -o json | jq -r '.items[] | select (.spec.clusterIP!="None")' | jq '.spec.clusterIP = "None"' | kubectl replace --force -f -
@mattdodge
mattdodge / add_ids.py
Last active May 8, 2018 19:36
Add IDs to nio blocks and services - migrate from nio 2.x to 3.0
# A script to add IDs to block and service resources.
# Useful for migrating a project from nio 2.x to 3.0
#
# Usage:
# Run this script from inside the etc/blocks or etc/services folders of your
# project
#
# Example:
# cd etc/blocks
# python add_ids.py