Skip to content

Instantly share code, notes, and snippets.

Avatar

Jahn Johansen need12648430

View GitHub Profile
@need12648430
need12648430 / l-system.scd
Created Oct 14, 2019
L-System in SuperCollider
View l-system.scd
// Instrument
(
SynthDef(\sine, {
arg freq = 440, amp = 0.5;
Out.ar(0, SinOsc.ar(freq, 0.0, amp * EnvGen.kr(Env.perc(0.01, 0.25), doneAction: 2)) ! 2);
}).add;
)
// Basic Stochastic L-System
(
@need12648430
need12648430 / build-templates.sh
Last active May 9, 2020
A script to build Godot export templates.
View build-templates.sh
#!/bin/bash
export EMSCRIPTEN_ROOT=[path containing em++, emsdk-portable/emscripten/*]
export ANDROID_HOME=[path to android sdk, usually /home/*/Android/Sdk]
export ANDROID_NDK_ROOT=[path to android ndk, likely $ANDROID_HOME/ndk-bundle]
X11_DEBUG=false
X11_RELEASE=false
WIN_DEBUG=false
WIN_RELEASE=false
@need12648430
need12648430 / example.js
Created Aug 15, 2016
Metaview - A tiny, fast, simplified abstraction of JS DataViews (similar to AS3's ByteArray)
View example.js
// writing
var o = new MetaView();
o.writeInt16(-128);
o.writeUint16(128);
o.writeFloat32(3.141592);
o.writeFloat32([1.5, 1.5]);
o.writeUTF8String("räksmörgås");
// saving
var s = o.finalize();
@need12648430
need12648430 / example.py
Last active Dec 2, 2015
Quarrel: WSGI-style routing for command line tools, in about 50 lines
View example.py
import sys
from quarrel import Quarrel
@Quarrel("multiply", int, int)
@Quarrel("multiply", int)
def multiply_int(a, b = 2):
print(a * b)
@Quarrel("greet", str)
def greet(name):
@need12648430
need12648430 / display.js
Last active Sep 1, 2015
Maze Generator in 532 bytes.
View display.js
// only semi-golfed, mostly because i was in the headspace; only used for debugging
var w, h, x, y, m=maze(w=16,h=16), g=[];
// generate fully walled grid
for(y = 0; y < h * 2 + 1; y ++) {
g[y]=[]
for(x = 0; x < w * 2 + 1; x ++)
g[y].push(!(y&1)?"#":!(x&1)?"#":" ");
}
@need12648430
need12648430 / ago.py
Last active Aug 29, 2015
User friendly representation of times in 12 lines of Python.
View ago.py
def ago(elapsed):
o = []
for unit, size in [("yr",365*24*60*60),("mo",30*24*60*60),("wk",7*24*60*60),("d",24*60*60),("hr",60*60),("min",60),("sec",1)]:
if size > elapsed: continue
total = int(elapsed / size)
elapsed = elapsed % size
o.append(str(total) + unit)
@need12648430
need12648430 / example.js
Last active Aug 29, 2015
tiny mustache-like templating engine in 2.6kb/108 loc
View example.js
var template = "{?condition}Condition exists! {condition}{/condition}\n\n" +
"{^whereami}I am not here!{/whereami}\n\n" +
"{#list}{name} is {age} years old! {?old}They are *old*!{/old}{!old}They are not old!{/old}\n{/list}";
console.log(stache(template, {
condition: "Hello world!",
list: [
{name: "Charles", age: "25"},
{name: "Bob", age: "42", old: true},
{name: "Samantha", age: "32"},
@need12648430
need12648430 / lcg.js
Last active Aug 29, 2015
Linear congruential generator (Seedable PRNG) with weighted choices and shuffling in 1.4kb of clean JS.
View lcg.js
var LCG = (function () {
var c = 0x93456789, a = 0x169659, mod, mask, r;
mask = (mod = Math.pow(2, 31)) - 1;
function LCG(seed) {
this.seed = seed || new Date().getTime();
}
LCG.prototype = {
nextInt:
@need12648430
need12648430 / shuffle.js
Last active Aug 29, 2015
Shuffle an Array in 1 line, 108 bytes of JavaScript
View shuffle.js
function shuffle(set){
for (var c=set.slice(0),o=[],m=Math; c.length > 0; o.push(c.splice(m.floor(m.random() * c.length), 1)[0]));
return o;
}
with (Math)
for (
// c becomes shallow copy of array
// o is output
var c=set.slice(0),o=[];
@need12648430
need12648430 / name.js
Last active Mar 9, 2019
Pronounceable Seeded Name Generator
View name.js
function name (id, l) {
function n(){return id=(399*id)%509}
var r="BDGKNPTVZ"[n()%9]
for (var i=1;i<l;i++) r+=i%2?"aeiou"[n()%5]:"bdgknptvz"[n()%9]
return r
};
// id=seed, l=length
function name (id, l) {
// lcg prng
You can’t perform that action at this time.