Skip to content

Instantly share code, notes, and snippets.

View mmatuson's full-sized avatar

Mitch Matuson mmatuson

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mmatuson on github.
  • I am mmatuson (https://keybase.io/mmatuson) on keybase.
  • I have a public key ASBZi77yCbURxNmQbo0w6KF9_kM-qicWp1YfB2ZZdF9Y-Ao

To claim this, I am signing this object:

"""
Instead of using a variable-time algorithm for comparing secrets,
you should be using constant-time algorithms.
via http://codahale.com/a-lesson-in-timing-attacks/
"""
def is_equal(a, b):
if len(a) != len(b):
return False;
@mmatuson
mmatuson / script_path.js
Created July 8, 2009 14:19
Dynamically get the path for any script in an HTML document.
/**
* Dynamically get the path for any script in an HTML document.
*/
var script_path = function(jsfile)
{
var src, path, scripts, re, i;
scripts = document.getElementsByTagName("script");
for (i = 0; i < scripts.length; i++)
{
@mmatuson
mmatuson / OrderedDict.py
Created June 7, 2009 17:51
A Simple dictionary that retains order in which the elements were added when you iterate over it
class OrderedDict(dict):
"""
A simple dictionary that retains order in which the elements were added when you iterate over it
"""
def __init__(self):
self._list = []
self._current = 0
super(OrderedDict,self).__init__()
def __setitem__(self, item, value):
@mmatuson
mmatuson / increment_filename.py
Created June 7, 2009 17:46
increment a file name
"""
increment a file name
"""
import os
import re
import glob
#regex to find the counter in a filename
RE_FILE_COUNTER = re.compile("\_(?P<i>[0-9]+)\.")