Skip to content

Instantly share code, notes, and snippets.

import cPickle as pickle
from UserDict import UserDict
class HashableDict(UserDict):
def __hash__(self):
return hash(pickle.dumps(dict([(k,self.data[k]) for k in sorted(self.data.keys())])))
>>> d1 = HashableDict({'a':1, 'b':2, 'c':3})
>>> d2 = HashableDict({'a':1, 'b':2, 'c':3})
>>> d3 = HashableDict({'a':1, 'b':2, 'c':4})
from json import JSONEncoder
from pymongo.objectid import ObjectId
class MongoEncoder(JSONEncoder):
def _iterencode(self, o, markers=None):
if isinstance(o, ObjectId):
return """ObjectId("%s")""" % str(o)
else:
return JSONEncoder._iterencode(self, o, markers)
from json import JSONEncoder
from pymongo.objectid import ObjectId
class MongoEncoder(JSONEncoder):
def _iterencode(self, o, markers=None):
if isinstance(o, ObjectId):
return """ObjectId("%s")""" % str(o)
else:
return JSONEncoder._iterencode(self, o, markers)
from json import JSONEncoder
from pymongo.objectid import ObjectId
class MongoEncoder(JSONEncoder):
def _iterencode(self, o, markers=None):
if isinstance(o, ObjectId):
return """ObjectId("%s")""" % str(o)
else:
return JSONEncoder._iterencode(self, o, markers)
@mumrah
mumrah / README.md
Last active September 15, 2015 14:35 — forked from enjalot/README.md
cosine similarity

Click on the various examples

Each example is a random vector in the same "space" as the sample in the top left.

Drag on individual rows

Each row represents one dimension of our vectors. You can drag them back and forth to change the value of our vector for that dimension.

Watch how the similarity bar changes

The bar below each vector is a measure of how similar it is to the sample in the top left.

Whats going on?

@mumrah
mumrah / OpenCVFPSTest.java
Created July 16, 2011 02:49
JavaCV: read FPS from a file
import static com.googlecode.javacv.cpp.opencv_highgui.*;
public class OpenCVFPSTest {
public static void main(String args[]) {
CvCapture capture = cvCreateFileCapture("big_buck_bunny_480p_surround-fix.avi");
double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
System.out.println("FPS: " + fps);
}
}
# Make the SVN repo:
svn mkdir protocol://path/to/repo
# Tell Git to track it (by default the SVN repo becomes the remote branch "git-svn"):
git svn init protocol://path/to/repo
git svn fetch
# Checkout the empty "git-svn" branch to a local integration branch:
git checkout -b svn-integration --track git-svn
# Merge the Git branch (non-fast-forwarded!) into the integration branch:
git merge --no-ff --no-commit feature
# Commit!
@mumrah
mumrah / index.html
Created September 15, 2011 17:12 — forked from enjalot/index.html
[d3cast] Simple Bar Chart example with d3.js
<!-- Annotated javascript available at http://enja.org/code/tuts/d3/bar -->
<!-- Code walkthrough screencast available at -->
<html>
<head>
<title>Enjalot's Bar</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.1.3"></script>
<style type="text/css">
.bar rect {
File propFile = new File("oozie.action.output.properties");
Properties props = new Properties();
props.put("foo", "bar");
OutputStream os = new FileOutputStream(propFile);
props.store(os, "");
os.close();
#!/bin/bash
(base64 -d | bash) <<EOF
IyEvYmluL2Jhc2gKCmVjaG8gImhlbGxvLCB3b3JsZCIK
EOF