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 matplotlib.pyplot as plt | |
import networkx as nx | |
G = nx.Graph() | |
wolf = 'wolf' | |
goat = 'goat' | |
rose = 'rose' | |
objects = [wolf, goat, rose] | |
boat = 'boat' |
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 matplotlib.pyplot as plt | |
rages = [] | |
def smooth(interable, size): | |
cache = interable[:size] | |
out = [] | |
for i in interable[size:]: | |
out.append(sum(cache)/size) |
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
# 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 |
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 collections | |
from contextlib import contextmanager | |
import sys | |
cypherText = '''HSCDIYCDXWSCWIYGYCHCWLRCOXGSC | |
BHKYACLCMLSCWIXCRLHBYACDXCRYLC | |
LSACIYCDXBACFRCXTCIHRCBHTYC | |
HSCDIYCBLSACXTCRFOMLGHSYR | |
''' |
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
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) ]) |
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 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 = { |
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 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) | |
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
# 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 |
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
# 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 |
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
// 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); |
OlderNewer