This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Module implemented restricted APIs based on graph types. | |
""" | |
_graph_types = set(['graph', 'multigraph', 'digraph', 'multidigraph']) | |
class MockModule(object): | |
""" | |
A mock module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Useful for students in need of block quotes for their paper, etc. | |
// Execute the line in your JavaScript console | |
new_window=window.open();new_window.document.body.innerHTML = $('iframe').contents().find('iframe').contents().find('body').get(1).innerHTML; | |
javascript:new_window=window.open();new_window.document.body.innerHTML = $('iframe').contents().find('iframe').contents().find('body').get(1).innerHTML; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
function uncrippleFrame() { | |
var body = this.contentWindow.document.getElementsByTagName('body')[0]; | |
this.contentWindow.onclick = null; | |
body._frame = this; | |
body.onmousemove = function() { | |
this._frame.contentWindow.onclick = null; | |
this.setAttribute('style', '-webkit-user-select: auto;'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
def line_graph(G, create_using=None): | |
# This code works only for multidigraphs | |
if create_using is None: | |
L = G.__class__() | |
else: | |
# Already instantiated. | |
L = create_using |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is free and unencumbered software released into the public domain. | |
# See UNLICENSE. | |
import numpy as np | |
import numpy.core.arrayprint as arrayprint | |
import contextlib | |
# | |
# cc-wiki | |
# http://stackoverflow.com/questions/2891790/pretty-printing-of-numpy-array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rolling_window(array, window=(0,), asteps=None, wsteps=None, axes=None, toend=True): | |
"""Create a view of `array` which for every point gives the n-dimensional | |
neighbourhood of size window. New dimensions are added at the end of | |
`array` or after the corresponding original dimension. | |
Parameters | |
---------- | |
array : array_like | |
Array to which the rolling window is applied. | |
window : int or tuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Some functions related to Bayesian networks (DAGs). | |
Most of this was pulled from: | |
http://www.mi.parisdescartes.fr/~nuel/bntworkshop2010/lecture3.pdf | |
""" | |
import networkx as nx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# original XML at http://www.w3.org/Math/characters/unicode.xml | |
# XSL for conversion: https://gist.github.com/798546 | |
unicode_to_latex = { | |
u"\u0020": "\\space ", | |
u"\u0023": "\\#", | |
u"\u0024": "\\textdollar ", | |
u"\u0025": "\\%", | |
u"\u0026": "\\&", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace | |
so it's better encapsulated. Now you can have multiple random number generators | |
and they won't stomp all over eachother's state. | |
If you want to use this as a substitute for Math.random(), use the random() | |
method like so: | |
var m = new MersenneTwister(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Callable | |
from cyordereddict import OrderedDict | |
class DefaultOrderedDict(OrderedDict): | |
# Source: http://stackoverflow.com/a/6190500/562769 | |
def __init__(self, default_factory=None, *a, **kw): | |
if (default_factory is not None and | |
not isinstance(default_factory, Callable)): | |
raise TypeError('first argument must be callable') | |
OrderedDict.__init__(self, *a, **kw) |
OlderNewer