Skip to content

Instantly share code, notes, and snippets.

@nopjia
nopjia / loadBufferProgressive.js
Created September 24, 2015 22:59
Progressive ArrayBuffer Loading
var stringToArrayBuffer = function(str, soffset, buf, boffset) {
var ui8a = new Uint8Array(buf, boffset);
for (var si = soffset, ai = 0; si < str.length; si++, ai++)
ui8a[ai] = (str.charCodeAt(si) & 0xff);
};
var loadBufferProgressive = function(url, cb) {
var req = new XMLHttpRequest();
req.open("GET", url);
req.overrideMimeType("text/plain; charset=x-user-defined");
@nopjia
nopjia / SimpleUpdateLoop.js
Last active August 29, 2015 14:10
SimpleUpdateLoop
var SimpleUpdateLoop = function() {
var _self = this;
var _requestId;
this.onUpdate = function(timestamp) {}; // function to implement
var _update = function(timestamp) {
_self.onUpdate(timestamp);
_requestId = window.requestAnimationFrame(_update);
};
@nopjia
nopjia / git-workflow.md
Last active August 29, 2015 14:07
Git Workflow
@nopjia
nopjia / python-cmd.py
Created September 29, 2014 22:48
Python Command-line
#!/usr/bin/python
import os, sys
def main():
# Command-line Processor
cmd_dir, cmd_name = os.path.split(os.path.abspath(sys.argv[0]))
cmd_args = sys.argv[1:]
class Singleton {
public:
static Singleton& getInstance()
{
static Singleton instance; // Guaranteed to be destroyed.
// Instantiated on first use.
return instance;
}
private:
Singleton() {}; // Constructor (the {} brackets) are needed here.