Skip to content

Instantly share code, notes, and snippets.

View TheAlchemist64's full-sized avatar

Daniel Sheppard TheAlchemist64

View GitHub Profile
@TheAlchemist64
TheAlchemist64 / graph.lua
Created August 26, 2018 16:03
Weighted directed graph in Lua
-- Uses adjacency list
local Graph = {}
Graph.__index = Graph
function Graph:new () return setmetatable({edges={}}, self) end
function Graph:addvertex (v)
if not self.edges[v] then
self.edges[v] = {}
@TheAlchemist64
TheAlchemist64 / sharedprop.js
Created March 15, 2018 00:31
This is a recursive JS function that checks if a property is shared between N number of objects. Uses rest parameters.
export default function sharedProp(p: string, ...objects: object[]){
if(objects.length == 0){
return false;
}
else if(objects.length == 1){
return objects[0].hasOwnProperty(p);
}
return objects[0].hasOwnProperty(p) && sharedProp(p, ...objects.slice(1));
}
@TheAlchemist64
TheAlchemist64 / ecs.js
Created October 8, 2017 21:11
A single file Javascript Entity Component System
/*
A Javascript port of the RDBMS-inspired Entity Component System found here:
https://github.com/adamgit/Entity-System-RDBMS-Inspired-Java/blob/master/EntitySystemJava/
src/com/wikidot/entitysystems/rdbmswithcodeinsystems/EntityManager.java
*/
export default class EntityManager {
constructor(){
this.lowestUnassignedID = 1;
@TheAlchemist64
TheAlchemist64 / enum.js
Created July 20, 2017 17:55
An Enum type for ES6
export default class Enum{
constructor(){
let args = Array.prototype.slice.call(arguments);
let i = 0;
args.forEach((val)=>{
this[val] = i++;
});
Object.freeze(this);
}
}