Skip to content

Instantly share code, notes, and snippets.

@NelsonMinar
NelsonMinar / bug-demo.py
Created January 20, 2015 01:51
Python bug with logging and multiprocessing with maxtasksperchild=1
'''Demo of a bug with multiprocessing.Pool, logging, and maxtasksperchild=1.
This program uses Pool.imap_unordered() to execute 200 tasks. Each worker
task writes a log message and sleeps a short time. The master process
uses a timeout on next() to log a status message occasionally.
When it works, 200 jobs are completed quickly. When it breaks, roughly
195 of 200 jobs will have completed and next() never raises StopIteration.
If everything logs to logging.getLogger() and maxtasksperchild=1, it
#!/usr/bin/env python2
"""Demonstrate a bug in unicodecsv with non-ASCII headers
In version 0.11.0 this works fine.
In version 0.11.1 it throws an error when writing the header."""
import unicodecsv
print "Unicode CSV version %s" % (unicodecsv.__version__)
fp = file("out.csv", "wb")
@NelsonMinar
NelsonMinar / coursera-ex6.ipynb
Created September 21, 2015 21:42
SVM with Gaussian experiements in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@NelsonMinar
NelsonMinar / README.mkd
Created September 25, 2010 21:24 — forked from mbostock/.block

Say you have a bunch of things, like thousands of photos from your digital camera. What if you wanted to look at them all at once? A typical user interface might order the photos chronologically by column and then by row, which does a decent job of grouping related photos together... But, if you have thousands of photos, the rows may be hundreds of photos long, and it is impossible to zoom in on a group of related photos!

An alternative that better preserves locality is a space-filling curve, such as the Hilbert curve. These curves can be used to place related things next to each other in space, avoiding those huge gaps across rows you see with sequential layout.

This example demonstrates the effect of using a Hilbert curve for layout with Polymaps by generating rainbow-colored tiles. As you can see, each tile is surrounded by its adjacent colors in the rainbow, even as you zoom in and ou

@NelsonMinar
NelsonMinar / index.html
Created September 10, 2011 00:57
Month selector demo
<!DOCTYPE html>
<html><head>
<title>Month control</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="month-selector.js"></script>
<style type="text/css">
#monthControl { font: 16px sans-serif; }
#monthControl g.month { cursor: pointer; }
@NelsonMinar
NelsonMinar / spawnvTimeout.py
Created November 27, 2011 19:00
Python spawnv() with timeout
#!/usr/bin/python
"""Simple module to implement spawnv with a timeout to kill the child.
Only tested on Unix. Probably won't play well with threads or many
child processes.
You can do much more subtle things with process management, but this is
easy and useful.
By Nelson Minar <nelson@monkey.org> 2004-04-11
"""
@NelsonMinar
NelsonMinar / index.html
Created December 7, 2011 00:38 — forked from mbostock/.block
selection.order
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.6.0"></script>
<script type="text/javascript">
d3.selection.prototype.order = function() {
@NelsonMinar
NelsonMinar / gist:1479133
Created December 14, 2011 23:41
Code to parse METARs with Tom Pollard's library
def extractWind(s):
"""Parse a metar and return wind speed, direction.
If gusts, reports peak speed. Variable wind direction reports prevailing."""
# clean the input
if s.endswith("="):
s = s[:-1]
if s.endswith(" LAST"):
s = s[:-5]
function fx(x, y) {
return x}
function fy(x, y) {
return y}
function fx(x, y) {
return x}
function fy(x, y) {
return 100*Math.log((1+Math.sin(y/90))/Math.cos(y/90))}