Skip to content

Instantly share code, notes, and snippets.

View raduGaspar's full-sized avatar

Radu B. Gaspar raduGaspar

View GitHub Profile
@raduGaspar
raduGaspar / basicNode.js
Created March 18, 2018 12:10
Barebones NodeJS Server
const http = require('http')
const port = process.env.PORT || 3001
http.createServer((req, res) => {
res.write('Hello World!')
res.end()
}).listen(port, () => {
console.log(`server start at port ${port}`)
})
@raduGaspar
raduGaspar / argsParser.js
Created April 10, 2017 10:08
Simple arguments parser
const args = ['-v', 'fileA', 'fileB', 'fileC', 'fileD', 'fileE', 'fileF', '-h', '-l', 'ro']; // process.argv.slice(2);
// supported arguments and their respective methods
const knownArgs = {
'-v': (files) => console.log('files', files),
'-l': (langs) => console.log('langs', langs),
'-h': () => console.log('help'),
};
// parse arguments and provided values
export default class PickerUtils {
/**
* Converts a hex color to RGB format
* @param {string} hex A hex color (shorthand allowed)
* @returns {object|null} Containing the RGB channels
*/
static hexToRGB(hex) {
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
const rgb = hex.replace(
shorthandRegex,
const decimalZip = (a, b) => {
const MAX_INT = 100000000;
if (typeof a !== 'number' || typeof b !== 'number') {
throw new Error('Only integers are allowed');
}
if (a < 0 || b < 0) {
throw new Error('Only positive integers are allowed');
}
if (a > MAX_INT || b > MAX_INT) {
throw new Error(`Integer value should not exceed ${MAX_INT}`);
import { Game, Scene, AssetsLoader } from '../engine';
import Player from './objects/Player';
import StarField from './objects/StarField';
import RockField from './objects/RockField';
import Map from './objects/Map';
import PlayerModel from './models/PlayerModel';
require('../../scss/styles.scss');
let assetsLoader = new AssetsLoader();
import { Scene, Particle } from '../../engine';
export default class Bullet extends Particle {
constructor(model) {
super(3, '#ff0');
this.x = model.x;
this.y = model.y;
this.angle = model.angle + Math.PI*0.5;
this.speed = 5;
this.created = Date.now();
import { Scene, DisplayObject, AssetsLoader, KeyboardEvents } from '../../engine';
import Bullet from './Bullet';
export default class Player extends DisplayObject {
constructor(model) { /* ... */ }
update() {
/* ... */
if(this.SPACE) {
this.model.fire = true;
import { DisplayObject } from '../../engine';
export default class Map extends DisplayObject {
constructor(markerSize=4, mapScaleFactor=0.2) {
super();
this.markerSize = markerSize;
this.mapScaleFactor = mapScaleFactor;
}
update() {
import { Scene, DisplayObject } from '../../engine';
import Rock from './Rock';
import RockModel from '../models/RockModel';
export default class RockField extends DisplayObject {
constructor(model, amount=10) {
super();
this.model = model;
this.amount = amount;
this.rocks = [];
import { Scene, DisplayObject } from '../../engine';
export default class Rock extends DisplayObject {
constructor(model) {
super();
this.model = model;
}
update() {