Skip to content

Instantly share code, notes, and snippets.

Hunter Loftis hunterloftis

Block or report user

Report or block hunterloftis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fizzbuzz.js
for (let i = 1; i <= 100; i++) {
const match = []
if (i % 3 === 0) match.push('fizz')
if (i % 5 === 0) match.push('buzz')
if (match.length === 0) match.push(i)
console.log(match.join(''))
}
View cli.go
// Start starts rendering based on CLI parameters
func (c Cli) Start() {
out := flag.String("out", "render.png", "Output png filename.")
concurrency := flag.Int("frames", runtime.NumCPU(), "Number of frames to combine.")
samples := flag.Float64("samples", math.Inf(1), "Average per pixel samples to take.")
heat := flag.String("heat", "", "Heatmap png filename.")
flag.Parse()
running := make(chan struct{})
ch := make(chan os.Signal, 2)
View spheres.go
func main() {
scene := trace.Scene{}
camera := trace.Camera{Width: 960, Height: 540}
sampler := trace.NewSampler(&camera, &scene, 10)
renderer := trace.NewRenderer(&camera)
light := trace.NewLight(1000, 1000, 1000)
redPlastic := trace.NewPlastic(1, 0, 0, 1)
bluePlastic := trace.NewPlastic(0, 0, 1, 1)
whitePlastic := trace.NewPlastic(1, 1, 1, 0)
silver := trace.NewMetal(0.972, 0.960, 0.915, 1)
View fibonacci-closure.go
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
prev := [2]int{0, 1}
return func() int {
n := prev[0]
View triadjs.html
<!doctype html>
<html>
<head>
<title>JS Paint</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; font-family: arial, sans-serif; }
body { background: #eee; }
#wrap { position: relative; margin: 50px auto 0 auto; width: 800px; }
#canvas { width: 800px; height: 600px; background: #fff; box-shadow: 1px 1px 32px #ddd; cursor: crosshair; }
#tools { position: absolute; width: 150px; top: 0; left: -150px; font-size: 18px; }
View pizza.js
async function makePizza(sauceType = 'red') {
let [ dough, [ sauce, cheese ]] = await Promise.all([ makeDough(), makeToppings(sauceType) ])
return dough.add(sauce).add(cheese)
}
async function makeToppings(sauceType) {
return [ await makeSauce(sauceType), await makeCheese() ]
}
View gist:06c23950ca44e616b76ae662406020cb
https://29a.ch/2010/5/17/path-tracing-a-cornell-box-in-javascript
https://29a.ch/sandbox/2010/cornellbox/worker.js
https://github.com/mateuszroth/raytracejs/blob/master/src/js/partials/raytrace.js
http://www.gabrielgambetta.com/tiny_raytracer_full.js
http://jupiter909.com/mark/jsrt.html
https://mzucker.github.io/2016/08/03/miniray.html
http://lousodrome.net/blog/light/tag/path-tracing/
http://create.stephan-brumme.com/smallpt-js/
http://blog.tojicode.com/2010/09/raytracing-in-javascript.html
https://benedikt-bitterli.me/tantalum/
View gist:d2e778e79a1568a37340d07dd5a83801
~ $ npm install --save interpret@0.5.2 --verbose
npm info it worked if it ends with ok
npm verb cli [ '/app/.heroku/node/bin/node',
npm verb cli '/app/.heroku/node/bin/npm',
npm verb cli 'install',
npm verb cli '--save',
npm verb cli 'interpret@0.5.2',
npm verb cli '--verbose' ]
npm info using npm@3.8.9
npm info using node@v6.2.0
View gist:f76266f1b0c92bcfba4f
// both the 'Player' component and this component exist as scripts on the player instance in the scene
// My guess is that start() is called on this component before on Player()
// (even though this script is listed last)
// Is this a bad pattern? It seems like running GetComponent() on each FixedUpdate() and checking for null would be a huge waste
// How do unity developers do this instead?
void start() {
player = GetComponent<Player>();
}
View gist:1c628ed7323caff9e046
v5.1.1:~/test/express (master)$ ied run start
/bin/bash: blah: command not found
start exited with status 127
v5.1.1:~/test/express (master *)$ npm start
> express@0.0.1 start /Users/hloftis/test/express
> blah
sh: blah: command not found
You can’t perform that action at this time.