Skip to content

Instantly share code, notes, and snippets.

View dmnsgn's full-sized avatar

Damien Seguin dmnsgn

View GitHub Profile
@dmnsgn
dmnsgn / es6-constructor.js
Created October 6, 2014 16:27
Douglas Crockford's constructor as explained in his NordicJS 2014 talk.
function constructor(spec) {
let {member} = spec,
{other} = other_constructor(spec),
method = function () {
// member, other, method, spec...
};
return Object.freeze({
method,
other
@dmnsgn
dmnsgn / .eslintrc.js
Created July 23, 2015 13:31
.eslintrc Google JavaScript Style Guide (eslint v0.24.1)
{
// http://eslint.org/docs/rules/
"env": {
"browser": true, // browser global variables.
"node": false, // Node.js global variables and Node.js-specific rules.
"worker": false, // web workers global variables.
"amd": false, // defines require() and define() as global variables as per the amd spec.
"mocha": false, // adds all of the Mocha testing global variables.
"jasmine": false, // adds all of the Jasmine testing global variables for version 1.3 and 2.0.
@dmnsgn
dmnsgn / NoClassSingleton.js
Last active April 16, 2016 17:35
ES6 singleton pattern: using objects
// http://www.2ality.com/2011/04/singleton-pattern-in-javascript-not.html
const NoClassSingleton = {
_instance: null,
get instance() {
if (!this._instance) {
this._instance = {
singletonMethod() {
return 'singletonMethod';
},
@dmnsgn
dmnsgn / SingletonDefaultExportInstance.js
Last active February 9, 2023 16:54
ES6 singleton pattern: module default exports an instance
class SingletonDefaultExportInstance {
constructor() {
this._type = 'SingletonDefaultExportInstance';
}
singletonMethod() {
return 'singletonMethod';
}
static staticMethod() {
@dmnsgn
dmnsgn / SingletonModuleScopedInstance.js
Created April 16, 2016 17:41
ES6 singleton pattern: constructor return an instance scoped to the module
// http://amanvirk.me/singleton-classes-in-es6/
let instance = null;
class SingletonModuleScopedInstance {
constructor() {
if (!instance) {
instance = this;
}
this._type = 'SingletonModuleScopedInstance';
@dmnsgn
dmnsgn / SingletonEnforcer.js
Created April 16, 2016 17:43
ES6 singleton pattern: use Symbol to ensure singularity
// http://stackoverflow.com/a/26227662/1527470
const singleton = Symbol();
const singletonEnforcer = Symbol();
class SingletonEnforcer {
constructor(enforcer) {
if (enforcer !== singletonEnforcer) {
throw new Error('Cannot construct singleton');
}
@dmnsgn
dmnsgn / SingletonNoInstance.js
Created April 16, 2016 17:46
ES6 singleton pattern: prevent the creation of an instance
// Implementation 4: prevent the creation of an instance
class SingletonNoInstance {
constructor(enforcer) {
throw new Error('Cannot construct singleton');
}
static singletonMethod() {
return 'singletonMethod';
}
@dmnsgn
dmnsgn / WebGL-WebGPU-frameworks-libraries.md
Last active May 5, 2024 16:18
A collection of WebGL and WebGPU frameworks and libraries

A non-exhaustive list of WebGL and WebGPU frameworks and libraries. It is mostly for learning purposes as some of the libraries listed are wip/outdated/not maintained anymore.

Engines and libraries ⚙️

Name Stars Last Commit Description
three.js ![GitHub
@dmnsgn
dmnsgn / listen_say_voices.sh
Created March 28, 2017 13:35
Listen to all voices available by the `say` command on macOS
for voice in `say -v '?' | awk '{print $1}'`; do say -v "$voice" "Hi `whoami` my name is ${voice}"; done
@dmnsgn
dmnsgn / listAllEventListeners.js
Created April 5, 2017 15:40
List all event listeners in a document
const listeners = (function listAllEventListeners() {
let elements = [];
const allElements = document.querySelectorAll('*');
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
}
for (let i = 0; i < allElements.length; i++) {
const currentElement = allElements[i];