Skip to content

Instantly share code, notes, and snippets.

@ENAML
ENAML / vector.js
Last active January 8, 2016 06:17
Simple Vector Class
/**
* Vector Class
*
*/
function Vector(x, y, angle, length) {
if (typeof x === "number" && typeof y === "number") {
this._x = x;
this._y = y;
@ENAML
ENAML / gist:e11c93bdcbe38847a1fce0cc083300bb
Created July 19, 2017 07:07
emscripten-openframeworks-3DPrimitivesExample-emmake-output
➜ 3DPrimitivesExample EMCC_DEBUG=1 emmake make -s VERBOSE=1
DEBUG:root:PYTHON not defined in /Users/enaml/.emscripten, using "/usr/local/opt/python/bin/python2.7"
DEBUG:root:JAVA not defined in /Users/enaml/.emscripten, using "java"
DEBUG:root:Cache: PID 12909 acquiring multiprocess file lock to Emscripten cache
DEBUG:root:Cache: done
DEBUG:root:Cache: PID 12909 released multiprocess file lock to Emscripten cache
DEBUG:root:check tells us to use asm.js backend
HOST_OS=Darwin
Compiling OF library for Release
HOST_OS=Darwin
@ENAML
ENAML / gist:7b132f1ccec4c5eabf4e3c3d4b05d009
Created July 19, 2017 07:12
emscripten-openframeworks-3DPrimitivesExample-emrun-error
➜ 3DPrimitivesExample emrun --browser chrome bin/3DPrimitivesExample.html
Executing /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --incognito --enable-nacl --enable-pnacl --disable-restore-session-state --enable-webgl --no-default-browser-check --no-first-run --allow-file-access-from-files http://localhost:6931/3DPrimitivesExample.html
[14682:36355:0719/031111.215804:ERROR:browser_gpu_channel_host_factory.cc(103)] Failed to launch GPU process.
-1
missing function: _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6assignEPKc
-1
warning: build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling
exception thrown: abort(-1) at Error
at jsStackTrace (http://localhost:6931/3DPrimitivesExample.js:1:23490)
at stackTrace (http://localhost:6931/3DPrimitivesExample.js:1:23661)
@ENAML
ENAML / gist:b2ed795cd0f5c069099ca5f2300ae6c7
Created July 19, 2017 07:29
emscripten-openframeworks-3DPrimitivesExample-emmake-output (after setting VERBOSE = 1 in emscripten/1.37.16/src/settings.js)
➜ 3DPrimitivesExample EMCC_DEBUG=1 emmake make -s DEMANGLE_SUPPORT=1 ASSERTIONS=1
DEBUG:root:PYTHON not defined in /Users/enaml/.emscripten, using "/usr/local/opt/python/bin/python2.7"
DEBUG:root:JAVA not defined in /Users/enaml/.emscripten, using "java"
DEBUG:root:Cache: PID 16629 acquiring multiprocess file lock to Emscripten cache
DEBUG:root:Cache: done
DEBUG:root:Cache: PID 16629 released multiprocess file lock to Emscripten cache
DEBUG:root:check tells us to use asm.js backend
HOST_OS=Darwin
Compiling OF library for Release
HOST_OS=Darwin
/*
Computes the next power-of-two integer greater than or equal to `num` via binary searching the bits
*/
const nextPOT = (num) => {
num = num | 0;
if (num === 0) {
return 0;
}
let min = 0;
let max = 64; // assume numbers in JS are no larger than 64 bits
@ENAML
ENAML / QuickSelect.java
Last active July 14, 2018 20:12
QuickSelect algo implementation in Java
public class QuickSelect {
// STATIC VARS
static Random rand = new Random();
/*
Tests
-----
*/
public static void main(String[] args) {
// run
const ctx = initCtx();
const text = `hello my friends`;
draw({ size: 16, fontFace: `monospace` }, text, 10, 50);
// initialize canvas context
function initCtx(w = 600, h = 400) {
// create canvas & ctx
const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
@ENAML
ENAML / game_of_life.re
Last active August 19, 2018 20:19
Conway's Game of Life in Reason.ml
/**
* Game of Life in Reason.ml
* =========================
*/
/**
* Coord
*/
module Coord = {
/* Type defs: */
@ENAML
ENAML / justify.js
Created August 28, 2018 02:59
justify-text-js
const { log } = console;
const SPACE = " ";
const isString = (val) => typeof val === 'string' || val instanceof String;
/**
* Justify Text
* ============
* TODO: description
*/
@ENAML
ENAML / HashableComparableEx.re
Last active December 11, 2020 11:52
creating custom ReasonML comparable / hashable types that can be used with Bucklescript's Belt Hash/Map/Set types
/*
ocaml src: https://bucklescript.github.io/bucklescript/api/Belt.html
*/
/* base type */
type intTuple = (int, int);
/* hashable tuple */
module TupleHashable = Belt.Id.MakeHashable({