Skip to content

Instantly share code, notes, and snippets.

@SeijiEmery
SeijiEmery / file1.js
Last active January 30, 2017 23:42
Hifi Script.include() "bug" (not a bug, ppl just don't understand how js + Script.include() works!)
var foo; // define local 'foo' with value undefined
var foo; // redeclaration (bug, but probably not illegal)
foo = 3; // assign to 3 in file1 scope
Script.include('file2.js') // gets run in its own scope
print(foo); // => 3
showFoo(); // => 1 (local foo bound in file2 scope)
@SeijiEmery
SeijiEmery / cstring_and_loops.cpp
Last active January 5, 2017 00:25
Partial cstring impl and for/while/do-while loop explanation
//
// Created on 10/5/2015 by Seiji Emery
//
// Reimplements cstring functions:
// http://www.cplusplus.com/reference/cstring/
//
//
// Pseudocode:
//
@SeijiEmery
SeijiEmery / fuzzy_search.py
Last active June 29, 2018 18:05
Fuzzy search
'''
Fuzzy search algorithm inspired by sublimetext.
'''
with open('/usr/share/dict/words') as f:
words = f.read().split('\n')
def fuzzy_match (q):
''' Match a query string q against a candidate string s, where len(q) <= len(s).
@SeijiEmery
SeijiEmery / example.cpp
Last active October 21, 2016 00:44
ResourceLayer example (for an internal project)
// Note on used types:
// - ResourceLayer is a threadsafe singleton class with a bunch of static methods
// - ResourceLayer calls return a Resource*******Request temp object, which uses a
// bunch of declarative chained method calls to set its state. The destructor (or
// an explicit call) launches the request.
// - TextureHandle wraps / owns a gl texture (the implementation is not important)
// - TextureHandleRef is a std::shared_ptr<TextureHandle>
// - There's some implicit path stuff (PROJECT_DIR is a path object; PROJECT_DIR + string => new path).
//
// Also, architecturally we're running in an environment with multiple threads, including
@SeijiEmery
SeijiEmery / gist:63f9219cb6093550c98c
Created February 24, 2016 21:24
full tokenizer regex for c-like languages
matches + splits string, int, hex, and floating point literals, c-style identifiers,
and greedily matches all symbols (differentiates between '+', '+=', '++').
Also includes two operators that I wish most languages _did_ have (you can remove these),
||= and &&=, which would codify/simplify the lua/js null check foo = x || default (foo ||= default)
('[^']*'|"[^"]*"|[_a-zA-Z][_a-zA-Z0-9]*|0x[a-fA-F\d]+|-?\d+(?:.\d+(?:[eE]\d+)?)?|//|/\*|\*/|\|\|=?|&&=?|\+\+|\-\-|\.\.|==|\->|[\+\-\*/%^\|&<>]=|[\?#\[\]\(\){}:;,\.\|&\+\-\*/%^<>=])
@SeijiEmery
SeijiEmery / extractmp3.py
Last active March 15, 2016 00:32
mp4 utils
#!/usr/bin/python
import os
from multiprocessing import Pool
NUM_THREADS = 8
cur_dir = '.'
src_formats = [ '.mp4' ]
dst_format = '.mp3'
conv_cmd = 'avconv -i "{0}" "{1}"'
@SeijiEmery
SeijiEmery / fubar.cpp
Last active April 3, 2016 07:57
minor d vs c++ comparison -- join() string function on variadic arguments
// List of template arguments to string
struct Joiner {
string sep;
stringstream ss;
Joiner (string sep) : sep(sep) {}
template <typename T, typename... Args>
Joiner& apply (const T & v, Args... args) {
ss << v << sep;
@SeijiEmery
SeijiEmery / gist:a6bfcdb3a80fc2c15926fdafb178d8cb
Last active January 30, 2017 23:22
spec for asm toy interpreter + oo runtime
Asm project idea: mini interpreter
LANGUAGE SPEC
types:
64-bit int
64-bit float (?)
"object" pointer
"closure" pointer
c pointer (?)
@SeijiEmery
SeijiEmery / bash
Created August 23, 2016 05:53
Interactive file compilation
when-changed foo.c "clear; clang -o foo foo.c > compile_log.txt && ./foo || cat compile_log.txt"
@SeijiEmery
SeijiEmery / gist:115f57ad45b5cf579e8078382f6c9d9b
Last active October 21, 2016 00:30
metacpp (concept for a c++ preprocessor that adds D-like features to the language)
meta-cpp: a custom c++ preprocessor that adds D-like features to c++11/c++14.
Nicer syntax:
class Foo { ... } => class Foo { ... };
interface Foo { void bar(); } => class Foo { virtual void bar() = 0; };
class Foo { this () { ... } } => class Foo { Foo () { ... } };
class Foo { => class Foo {