Skip to content

Instantly share code, notes, and snippets.

View raduGaspar's full-sized avatar

Radu B. Gaspar raduGaspar

View GitHub Profile
@raduGaspar
raduGaspar / package.js
Created March 27, 2016 15:20
nw-builder package logic for nwjs desktop applications
var NwBuilder = require('nw-builder'),
buildsDir = 'c:/builds',
opts = {
files: './dist/**', // use the glob format
version: '0.12.0',
buildDir: buildsDir + '/build/',
cacheDir: buildsDir + '/cache/',
platforms: ['win64', 'osx64', 'linux64']
},
nw = new NwBuilder(opts);
class Animal {
swim() {
console.log('swimming');
}
eat() {
console.log('eating');
}
sleep() {
console.log('sleeping');
}
const swimmer = (state) => ({
swim: () => console.log(state.name, 'is swimming')
})
const eater = (state) => ({
eat: () => console.log(state.name, 'is eating')
})
const sleeper = (state) => ({
sleep: () => console.log(state.name, 'is sleeping')
@raduGaspar
raduGaspar / dp-decorator.js
Created May 25, 2016 13:55
Decorator design pattern example
// Design Patterns: Decorator
class Drink {
constructor() {
this.total = function() {
return 0;
}
}
}
// decorator 1
let EventDispatcher = (function() {
let instance = null;
class EventDispatcher {
constructor() {
if(!instance) {
instance = this;
}
return instance;
@raduGaspar
raduGaspar / dylg2-game.js
Created October 24, 2016 17:08
A simple Game class which accepts multiple scene elements and updates them in a game loop
export default class Game {
constructor(scenes) {
// check if the browser supports requestAnimationFrame
if(!(typeof requestAnimationFrame)) {
throw new Error('Your browser doesn\'t support requestAnimationFrame :(');
}
this.scenes = [];
this.addScenes(scenes);
this.play();
import Utils from './Utils';
let assetLoaderInstance;
export default class AssetsLoader {
constructor() {
if(!assetLoaderInstance) {
console.log('AssetsLoader instance created');
this.assets = {};
assetLoaderInstance = this;
export default class Utils {
constructor() {
let e = new Error('is a static class, no need to instantiate!');
e.name = 'Utils';
throw e.toString();
}
static toCamelCase(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(letter, index) {
let pubSubInstance;
const subjects = {};
const hOP = subjects.hasOwnProperty;
class PubSub {
constructor() {
if(!pubSubInstance) {
console.log('EventDispatcher instance created');
pubSubInstance = this;
}
import { KeyboardEvents, EventDispatcher } from '../'
let keyboardInstance;
let keysMap = {};
class KeyboardSingleton {
constructor() {
if(!keyboardInstance) {
console.log('Keyboard instance created');
keyboardInstance = this;