Skip to content

Instantly share code, notes, and snippets.

View fish2000's full-sized avatar
👉
My Python work is on the Mars helicopter, and ubiquitous on earth, and more!!!!

Alexander Böhn fish2000

👉
My Python work is on the Mars helicopter, and ubiquitous on earth, and more!!!!
  • Objects in Space and Time, LLC
  • Baltimore, MD
  • 21:27 (UTC -04:00)
  • X @fish2000
View GitHub Profile
@fish2000
fish2000 / example.txt
Created October 15, 2010 22:21
directory-recursive file suffix frequency histograms
First example: no args, lists all suffixes, use defaults for: directory (current working directory), sort order (alphabetical), graph character ('-'), graph width (50 chars).
Second example: -n (sort by file count), -t 20 (list only the top 20 suffixes), --width=35 (scale graph width to 35 chars), --imatch="^\w{3,4}$" (case-insensitive regexp -- only print suffixes that are between 3 and for chars in length), -g \* (specify a new graph character). unflagged arguments are assumed to be directories to be scanned.
See the source for all options.
OTUS-ASIO:face fish$ alias sufs='/wherever/you/put/getfilesuffixes.py'
OTUS-ASIO:face fish$ sufs
>>> /this/current/directory (total 47846)
=== 21 -
@fish2000
fish2000 / flushemailqueue.py
Created October 16, 2010 10:51
Database email queue
#!/usr/bin/env python
# encoding: utf-8
import sys, os, getopt
from django.core.management import setup_environ
import settings
setup_environ(settings)
from django.db.models import Q
@fish2000
fish2000 / hirelite.py
Created October 28, 2010 14:50
my solution to the 'prove you are a programmer' question that hirelite.com posed to me when registering
#!/usr/bin/env python
# encoding: utf-8
def hirelite(i):
if not i % 4:
if not i % 7:
return "rickroll"
return "rick"
if not i % 7:
return "roll"
@fish2000
fish2000 / xrange.js
Created December 8, 2010 21:31
JavaScript (approximate) implementation of Python xrange() builtin
function xrange(b0, b1, quanta) {
if (!quanta) { quanta = 1; }
if (!b1) { b1 = b0; b0 = 0; }
out = [];
for (var i = b0, idx = 0; i < b1; i += quanta, idx++) {
out[idx] = i;
}
return out;
}
@fish2000
fish2000 / ffffound-feedparse.py
Created December 15, 2010 03:21
how to parse it
>>> ffeed = feedparser.parse('http://ffffound.com/home/fish2000/recommend/feed?offset=50')
>>> [os.path.basename(pq(v).find('img').attr('src')).split('_')[0] for k, v in reduce(lambda a,b: a+b, [fe.items()[0][1].items() for fe in ffeed.entries]) if k == 'value']
['e391fa402eacb755f200a6f85bc6cbf61a0b1e5b', 'c6fea29870500b4a3d2d84669c0b8b43c10cd017', 'f133e22b5c3c4ffcd492582bea01bad49300d102', '1d7dfd992de34ed5d0f0deffcabe918de543b2ee', 'a4d98a1e1d1aad4507c16e1d6fb265eb0256bdee', '9bc393e7832764c4ac50
3f97b4f9817893eaf4a8', 'd81e5468d113dea6b5891b1e0959b952ebd9951b', '9e1655515a57c090fe2e3dfee66b5c40d883c55f', '3001624270c16697ecfe6db5807fcd128772eb3a', 'ed868a5311c985a86970b1770819affc169d3ab8', '48389c1de0ec1cc146b5f9967f32864b397a0f19',
'5bd90a15c37fff46f9a057efb722514ca4d509d7', 'c61449bf5937d7461e849734843f6b2b5f9dee10', '2fdc12eaf38a47839ea4f58e9c482a1be5fcaac9', '30f10010e49d7a3544eae5c3d824e188171fed53', '19eba6d9996c7fd112001f1e778b16578552ad99', '462f7d09eb4a3d56cf2c
7ed0cb42f1ce297a08ad', '27d8e3a4
@fish2000
fish2000 / delicious-backup-2-json.py
Created December 17, 2010 16:56
Exporting from delicious.com (née del.icio.us) gives you crap HTML, this script reorganizes it into a JSON structure suitable for the high standards we have for datastructures here at the end of 2010.
#!/usr/bin/env python
# get it from https://secure.delicious.com/settings/bookmarks/export
# use the default options
# file will be named with a datestamp, like: 'delicious-YYYYMMDD.htm'
import os, re, site, sys
from BeautifulSoup import BeautifulSoup
try:
import json
except ImportError:
@fish2000
fish2000 / goodnightsweetaggregation.js
Created December 23, 2010 17:49
no longer necessary -- but some snippets you're fond of, in spite of their unapologetic sprawling impracticality.
var deltadata = _(chart_data.get_series()).map(function (i) {
return i.data;
}).reduceRight(function (a,b) {
return a.concat(b);
}).map(function (i) {
return i[1];
}).reduce(function (a,b) {
return a + b;
});
@fish2000
fish2000 / and-fuck-launchctl-too-XML-is-so-1998-you-guys.plist
Created June 4, 2011 16:01
Build your own Snow-Leopard-tastic apache2 httpd from source and install in /usr/local with no ppc-universal-binary crapola
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- this goes in a file such as /System/Library/LaunchDaemons/ost.apache2.plist -->
<dict>
<key>Label</key>
<string>ost.apache2</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/apachectl</string>
@fish2000
fish2000 / failed-coreutils-build-output.txt
Created June 9, 2011 02:38
Coreutils build fails in uptime.c (looks like it could be a syntax error but I'm not sure)
OTUS-ASIO:tmp$ brew install coreutils
==> Downloading ftp://ftp.gnu.org/gnu/coreutils/coreutils-8.12.tar.gz
File already downloaded in /Users/fish/Library/Caches/Homebrew
==> ./configure --prefix=/usr/local/Cellar/coreutils/8.12 --program-prefix=g
==> make install
make install-recursive
Making install in lib
GEN arg-nonnull.h
GEN alloca.h
GEN c++defs.h
@fish2000
fish2000 / msgpack-roundtrip.py
Created September 9, 2011 20:04
Something to keep in mind w/r/t msgpack-vs.-json
>>> {'yo': ('dogg','yodogg', ['i', 'heard', 'you', 'liked'])}
{'yo': ('dogg', 'yodogg', ['i', 'heard', 'you', 'liked'])}
>>> dic = {'yo': ('dogg','yodogg', ['i', 'heard', 'you', 'liked'])}
>>> msgpack.dumps(dic)
'\x81\xa2yo\x93\xa4dogg\xa6yodogg\x94\xa1i\xa5heard\xa3you\xa5liked'
>>> packitup = msgpack.dumps(dic)
>>> msgpack.loads(packitup)
{'yo': ('dogg', 'yodogg', ('i', 'heard', 'you', 'liked'))}
>>> msgpack.loads(packitup) == dic
False