Skip to content

Instantly share code, notes, and snippets.

View tcsavage's full-sized avatar
🦡

Tom Savage tcsavage

🦡
View GitHub Profile
@tcsavage
tcsavage / gist:4078346
Created November 15, 2012 12:10
Sphere intersection snippet
{-
Minimum distance for ray intersection to be considered important.
This is due to limited numerical precision with floating point numbers. A ray could be reflected and then be immediately registered as intersecting with the object it just bounced off.
-}
epsilon :: Scalar
epsilon = 0.1
{-|
Defines a mathematical sphere.
-}
@tcsavage
tcsavage / Maybe.cpp
Created December 12, 2012 16:09 — forked from anonymous/Maybe.cpp
Added `bind` function using C++11 lambdas.
#include <iostream>
#include <functional>
// Polymorphic Maybe type.
template <typename T>
class Maybe
{
public:
// Returns True if Maybe contains a value.
virtual bool isJust() = 0;
@tcsavage
tcsavage / MonadTransformersExample.hs
Last active March 25, 2022 19:44
Example of ReaderT monad transformer
module Main where
import Control.Monad (replicateM)
import Control.Monad.Trans (lift)
import Control.Monad.Reader (ReaderT, ask, runReaderT)
import Control.Monad.Random (Rand, getRandomR, evalRand)
import System.Random (getStdGen, StdGen)
import Text.Printf
op :: ReaderT Int (Rand StdGen) String
test :: Int -> [Int]
test f
| f <= 0 = []
| otherwise = f : test (f-1)
Build LeapC of project LeapC with configuration Debug
CompileC build/LeapC.build/Debug/LeapC.build/Objects-normal/x86_64/leap_controller.o ../src/leap_controller.cpp normal x86_64 c++ com.apple.compilers.gcc.4_2
cd /Users/tom/Documents/LeapC/xcode
setenv LANG en_US.US-ASCII
/Developer/usr/bin/gcc-4.2 -x c++ -arch x86_64 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -Wuninitialized -Wshorten-64-to-32 -DDEBUG=1 -isysroot /Developer/SDKs/MacOSX10.6.sdk -fvisibility-inlines-hidden -mmacosx-version-min=10.6 -gdwarf-2 -iquote /Users/tom/Documents/LeapC/xcode/build/LeapC.build/Debug/LeapC.build/LeapC-generated-files.hmap -I/Users/tom/Documents/LeapC/xcode/build/LeapC.build/Debug/LeapC.build/LeapC-own-target-headers.hmap -I/Users/tom/Documents/LeapC/xcode/build/LeapC.build/Debug/LeapC.build/LeapC-all-target-headers.hmap -iquote /Users/tom/Documents/LeapC/xcode/build/LeapC.build/Debug/LeapC.build/LeapC-project-headers.hmap -F/Users/tom/Documents/LeapC/xcode
@tcsavage
tcsavage / primaility.hs
Last active December 14, 2015 10:19
Testing time complexity of different primality tests
module Main where
import Criterion.Main
-- We're going to use this constant as a known prime to test our functions with.
testPrime :: Int
testPrime = 16127
-- And a known non-prime as well.
testNonPrime :: Int
trait Monoid {
static fn mempty() -> self;
fn mappend(other: self) -> self;
}
impl int: Monoid {
static fn mempty() -> int { 0 }
fn mappend(other: int) -> int { self + other}
}
\begin{landscape}
\begin{longtable}{|l|p{120pt}|p{120pt}|p{120pt}|p{120pt}|}
\caption{Functional Requirements} \\
\hline
\textbf{ID} & \textbf{What} & \textbf{How} & \textbf{Test} & \textbf{Expected Result} \\ \hline
\endfirsthead
\multicolumn{4}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{ID} & \textbf{What} & \textbf{How} & \textbf{Test} & \textbf{Expected Result} \\ \hline
@tcsavage
tcsavage / diffuseM.hs
Created May 6, 2013 14:42
Diffuse shading with shadows
diffuseM :: Colour -> Material () (BSDF Colour)
diffuseM col = proc () -> do
out <- diffuse -< col -- Get diffuse shading
shad <- traceM <<< getInidentRay -< () -- Test path to light
returnA -< maybe holdout (\(_,_,_,e) -> if e then out else holdout) shad -- Set BSDF to black if in shadow
@tcsavage
tcsavage / lengthindexed.cpp
Last active August 29, 2015 14:00
Length-indexed list type
#include <iostream>
#include <functional>
#include <memory>
#include <assert.h>
// Based on Bartosz Milewski's immutable list class.
// http://bartoszmilewski.com/2013/11/13/functional-data-structures-in-c-lists/
// Defined externally to List because it needs to be independent from the size parameter.
template <typename T>