Skip to content

Instantly share code, notes, and snippets.

@nsfmc
nsfmc / dice.py
Last active August 29, 2015 04:18
get some diceware numbers
import argparse
import random
def dicenumber():
"""return a 5-digit number suitable for diceware
the 5-digit integer contains only the digits 1-6
"""
return int(''.join([str(random.randrange(1, 7)) for x in range(5)]))

Keybase proof

I hereby claim:

  • I am nsfmc on github.
  • I am nsfmc (https://keybase.io/nsfmc) on keybase.
  • I have a public key whose fingerprint is 55CF 0365 F98C 2904 200A 7034 22D2 16D1 9B7C 45A7

To claim this, I am signing this object:

<!-- one image
you could imagine, for example,
icon.svg#tiny referring to an icon for display on 3x3" display
icon.svg#small referring to an icon on a portrait-oriented phone
icon.svg#default referring to an icon that will be large enough to resolve all detail
-->
<picture>
<source media="(max-width: 12em)" src="icon.svg#tiny">
<source media="(max-width: 24em)" src="icon.svg#small">
@nsfmc
nsfmc / A-Pen-by-Marcos-Ojeda.markdown
Last active August 29, 2015 13:57
A Pen by Marcos Ojeda.
@nsfmc
nsfmc / toggleEndian.js
Created March 25, 2014 19:24
am i the only person that wants to be able to do Buffer("foo", "utf16-be")?
/**
* returns a new buffer with toggled endianness
* @param {Buffer} buff a nodeJS buffer, presumably utf16le/ucs2
* @return {Buffer} a nodeJS buffer, probably utf16be
*/
function toggleEndian(buff){
out = []
for (var i = 0; i < buff.length; i+=2) {
out[i] = buff[i + 1];
out[i + 1] = buff[i];
@nsfmc
nsfmc / ka-auto.py
Created September 8, 2014 19:10
a plotdevice file for making stuff with the ka api
"""
ka design automation tools -
super rough, but this is a set of functions, documented at the bottom,
which let you get the text/names of topics/subjects/domains for parts of
our topic tree.
you need to get the topic tree, which you can do by running
curl -o ~/topictree.json http://www.khanacademy.org/api/v1/topictree
@nsfmc
nsfmc / README.md
Last active August 29, 2015 14:06 — forked from mbostock/.block

A treemap recursively subdivides area into rectangles; the area of any node in the tree corresponds to its value. This example uses color to encode different packages of the Flare visualization toolkit. Treemap design invented by Ben Shneiderman. Squarified algorithm by Bruls, Huizing and van Wijk. Data courtesy Jeff Heer.

@nsfmc
nsfmc / README.md
Last active August 29, 2015 14:06 — forked from mbostock/.block

A treemap recursively subdivides area into rectangles; the area of any node in the tree corresponds to its value. This example uses color to encode different packages of the Flare visualization toolkit. Treemap design invented by Ben Shneiderman. Squarified algorithm by Bruls, Huizing and van Wijk. Data courtesy Jeff Heer.

@nsfmc
nsfmc / contentsize.py
Last active August 29, 2015 14:06
getting sizes (amount of content) for each subject in khan academy
# getting relative size of each subject in math using
# http://www.khanacademy.org/api/v1/topictree and helper
# methods from https://gist.github.com/nsfmc/2a877c61f0f7da984ead
# to plug into something like https://gist.github.com/nsfmc/2d496c1bb9e096402f8e
output = []
for s in subjects_for_domain('math'):
count = 0
for t in get_topics(domain='math', subject=s['slug']):
for tut in t['children']:
@nsfmc
nsfmc / horizontal-grids.py
Last active August 29, 2015 14:07
a plotdevice file for gridding out domains and subjects
from ka_automation import *
# yeesh, gross!!!
def random_domain_color(slug, **kwargs):
import random
seed = kwargs.get('seed', 53)
print seed
random.seed(seed)
subject_count = len(subjects_for_domain(slug))