Skip to content

Instantly share code, notes, and snippets.

@glyphobet
glyphobet / jython_crasher.py
Created September 22, 2011 10:19
This crashes Jython (2.5.2 final), without a trailing newline at the end of the file. With the newline, it's fine. In CPython, it's fine with or without the trailing newline. Reported to Jython in: http://bugs.jython.org/issue1812
class Foo(object):
def foo(arg):
pass
# comment
@glyphobet
glyphobet / tiny.js
Created July 26, 2011 01:02
Firefox bookmarklet to get the current page's short URL, if one is defined. If no short URL is defined, gives you the option of getting one from TinyURL instead.
(function(){
var promptURL=function (url){
window.prompt("Copy short URL to clipboard:",url);
};
var links=document.getElementsByTagName('link');
for(var i=0;i<links.length;i++){
var tag=links[i];
if(tag.getAttribute('rel')=='shorturl' || tag.getAttribute('rel')=='shortlink' || tag.getAttribute('id')=='shorturl' || tag.getAttribute('id')=='shortlink'){
promptURL(tag.getAttribute('href'));
return;
@glyphobet
glyphobet / hoover.py
Created July 21, 2011 04:59
Remove emacs poop and cruft lying around from mounting Linux filesystems on Mac OS X over sshfs
#!/usr/bin/env python
import sys
import os
import os.path
for a in sys.argv[1:]:
for root, dirs, files in os.walk(a):
for f in files:
if f.startswith(':2e_') or f.startswith('._') or f.endswith('~') or f == '.DS_Store':
print "rm %r" % os.path.join(root, f)
@glyphobet
glyphobet / 2dqueries.js
Created May 10, 2011 08:48
Example showing that MongoDB uses native units for regular 2d queries, and radians for spherical 2d queries
> db.dropDatabase();
{ "dropped" : "test", "ok" : 1 }
>
> // These points are one degree apart, which (according to Google Maps) is about 110 km apart
> // at this point on the Earth.
> db.points.insert({location: [-122, 37]});
> db.points.insert({location: [-122, 38]});
> db.points.ensureIndex({location:"2d"});
>
>