Skip to content

Instantly share code, notes, and snippets.

View DomNomNom's full-sized avatar

DomNomNom DomNomNom

View GitHub Profile
@DomNomNom
DomNomNom / MatrixSpline.py
Created December 5, 2014 04:41
Creating a spline with just a linear system
import numpy as np
import matplotlib.pyplot as plt
import scipy.sparse as sparse
import scipy.sparse.linalg
xs = [25.0, 50.0, 60.0]
ys = [ 1.0, -1.0, 0.3]
@DomNomNom
DomNomNom / periodicEvent.py
Created November 17, 2014 10:31
An example of having a function being called regularly while still processing user input
'''
An example of having a function being called regularly
while still processing user input
'''
import threading
# the regular event
timer = None
@DomNomNom
DomNomNom / rotationIdentity.cpp
Last active August 29, 2015 14:06
Rotation identity
// why does makeTransform1 give the same results as makeTransform2?
mat3 rotationMatrix(float angle, vec3 axis) {
... // returns a 3x3 rotation matrix for rotating about the given axis
}
mat3 makeTransform1(float alpha, float beta, float gamma) {
mat3 alphaTransform = rotationMatrix(alpha, vec3(0.0, 1.0, 0.0));
mat3 betaTransform = rotationMatrix(beta, vec3(1.0, 0.0, 0.0));
@DomNomNom
DomNomNom / SaneCode.cpp
Created August 28, 2014 02:58
Underhanded stuff in C++. No warnings from the compiler
// curtesy of https://github.com/DavidSaxon and http://www.parashift.com/c++-faq-lite/
#include <iostream>
// this function will be called by the base class
void baseFunction() {
std::cout << "Base Class!" << std::endl;
}
@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);
# 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 / 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
@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)
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 = {
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) ])