Skip to content

Instantly share code, notes, and snippets.

View DomNomNom's full-sized avatar

DomNomNom DomNomNom

View GitHub Profile
import matplotlib.pyplot as plt
import networkx as nx
G = nx.Graph()
wolf = 'wolf'
goat = 'goat'
rose = 'rose'
objects = [wolf, goat, rose]
boat = 'boat'
import matplotlib.pyplot as plt
rages = []
def smooth(interable, size):
cache = interable[:size]
out = []
for i in interable[size:]:
out.append(sum(cache)/size)
@DomNomNom
DomNomNom / ContextManagerExample.py
Last active December 25, 2015 08:19
Context Manager
# custom context manager
import contextlib, sys
p = sys.stdout.write # shorthand for print (without spaces)
@contextlib.contextmanager
def printcolour(colour):
p('\033[{0}m'.format(colour))
yield
import collections
from contextlib import contextmanager
import sys
cypherText = '''HSCDIYCDXWSCWIYGYCHCWLRCOXGSC
BHKYACLCMLSCWIXCRLHBYACDXCRYLC
LSACIYCDXBACFRCXTCIHRCBHTYC
HSCDIYCBLSACXTCRFOMLGHSYR
'''
actions = {
(False, False) : lambda x: x,
(True, False) : lambda x: "fizz",
(False, True ) : lambda x: "buzz",
(True, True ) : lambda x: "fizzBuzz",
}
print '\n'.join([ actions[x%3==0, x%5==0](x) for x in xrange(1,101) ])
from datetime import datetime, timedelta
import os
import traceback
# This code is called when instances of this SOP cook.
node = hou.pwd()
geo = node.geometry()
myLocals = {
@DomNomNom
DomNomNom / oneLiner.py
Created June 3, 2014 11:55
Lots of documentation for a one-liner
import numpy as np
'''
Solves matrix M in the following equation given matricies A and B:
MA = B
A.shape == B.shape == (m, n)
M.shape = (n, n)
@DomNomNom
DomNomNom / big.py
Created August 1, 2014 11:36 — forked from anonymous/big.py
# a recursive function that produces big numbers. What is the time complexity of this?
def big(a, b, depth):
if depth == 0:
return a*b # assume this takes one unit of time
out = 1
for i in xrange(b): # repeat the following b times
out = big(a, out, depth-1)
return out
# a recursive function that produces big numbers. What is the time complexity of this?
def up(a, b, depth):
if depth == 0:
return a*b # assume this takes one unit of time
out = 1
for i in xrange(b): # repeat the following b times
out = up(a, out, depth-1)
return out
@DomNomNom
DomNomNom / intersectAABB.glsl
Last active October 3, 2024 09:02
Ray-AABB (Axis Aligned Bounding Box) intersection.
// adapted from intersectCube in https://github.com/evanw/webgl-path-tracing/blob/master/webgl-path-tracing.js
// compute the near and far intersections of the cube (stored in the x and y components) using the slab method
// no intersection means vec.x > vec.y (really tNear > tFar)
vec2 intersectAABB(vec3 rayOrigin, vec3 rayDir, vec3 boxMin, vec3 boxMax) {
vec3 tMin = (boxMin - rayOrigin) / rayDir;
vec3 tMax = (boxMax - rayOrigin) / rayDir;
vec3 t1 = min(tMin, tMax);
vec3 t2 = max(tMin, tMax);
float tNear = max(max(t1.x, t1.y), t1.z);