Skip to content

Instantly share code, notes, and snippets.

View mscuthbert's full-sized avatar

Michael Scott Asato Cuthbert mscuthbert

View GitHub Profile
@mscuthbert
mscuthbert / music21_setup.ipynb
Last active November 11, 2022 13:24
music21_setup.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mscuthbert
mscuthbert / likely_python_module.py
Created September 7, 2018 20:14
Get likely Python module name
import pathlib
def likely_python_module(filename):
'''
Given a filename or Path, return the "likely" python module name. That is, iterate the
parent directories until it doesn't contain an __init__.py file.
Python 3.4+ only (uses pathlib), but then again, it's only Python 3 where
no relative imports causes this problem!
'''
@mscuthbert
mscuthbert / thingsToCal.scpt
Created June 26, 2016 19:41
Javascript for Automation (JXA) task to take Cultured Code Things Today list tagged with times and put it in calendar
/**
* ThingsToCal -- Copyright (c) 2016 Michael Scott Cuthbert
* Released under a BSD License
*
*/
ObjC.import("stdlib");
class ThingsOrganizer {
constructor() {
@mscuthbert
mscuthbert / usedCar.py
Created January 9, 2016 10:56
Swindling Car Dealers
# http://fivethirtyeight.com/features/how-badly-can-a-car-salesman-swindle-you/
# Michael Scott Cuthbert (cuthbert@mit.edu) -- CC-BY 2015
from __future__ import print_function, division
import itertools
from collections import OrderedDict
from pprint import pprint
inf = float('inf')
@mscuthbert
mscuthbert / main.js
Created October 9, 2015 13:57
Markdown links in Jupyter/IPython
// Allow sphinx rst references in markdown cells
// TODO: Markdown cells will only be reevaluated when a notebook is dirty
// (i.e. you have made changes). If you save it before reevaluating MD cells,
// they will show the old value.
define([
'base/js/namespace',
'jquery',
'notebook/js/cell',
'base/js/security',
class X(object):
__slots__ = ('hi',)
class Y(X):
__slots__ = ('bye',)
x = X()
print(x.__slots__)
# ('hi',)
@mscuthbert
mscuthbert / optionalFraction.py
Last active August 29, 2015 14:03
Get the best speed out of either a float (int) or Fraction object depending on what level of precision is necessary.
from fractions import Fraction
DENOM_LIMIT = 65535
def _preFracLimitDenominator(n, d):
'''
copied from fractions.limit_denominator. Their method
requires creating three new Fraction instances to get one back. this doesn't create any
call before Fraction...
DENOM_LIMIT is hardcoded to defaults.limitOffsetDenominator for speed...
@mscuthbert
mscuthbert / mainTest.py
Created June 15, 2014 22:38
Doctest runner compatible between Python 2 & 3 -- deals with some major differences.
def mainTest(*testClasses, **kwargs):
'''
Takes as its arguments modules (or a string 'noDocTest' or 'verbose')
and runs all of these modules through a unittest suite
Unless 'noDocTest' is passed as a module, a docTest
is also performed on `__main__`, hence the name "mainTest".
If 'moduleRelative' (a string) is passed as a module, then
global variables are preserved.