Skip to content

Instantly share code, notes, and snippets.

View caracal7's full-sized avatar

Dmitrii Vasilev caracal7

  • This planet
View GitHub Profile
@caracal7
caracal7 / LICENSE.txt
Created January 26, 2018 21:05
This is a basic, cross-platform, valid Node.js EventEmitter.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Vitron Prince
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@caracal7
caracal7 / README.md
Created January 26, 2018 21:15 — forked from williammalo/README.md
The cleanest, easiest dom api ever! It will change your life!

I always thought there was a better way to access the dom. This is a tool that allows you to use extremely simple syntax to access dom elements. It makes an object with the name of your choice (I chose "$") that contains a reference to all elements that have an id.

example:

<script> $.foo.innerHTML = "Hello world" </script>

You can even choose to use an object that already exists (I chose "document" because it makes sense)

@caracal7
caracal7 / geotic.js
Created January 26, 2018 21:44 — forked from ddmills/geotic.js
Component-Entity-System
let _id;
const id = () => {
let now = Date.now();
if (now <= _id) now++;
_id = now;
return now;
}
const hash = (n) => n.sort((a, b) => a > b).join('$');
const remove = (a, v) => a.splice(a.indexOf(v), 1);
@caracal7
caracal7 / gist:e30c206724674bd11fa8b735df4efd5d
Created January 26, 2018 21:50 — forked from ThaisRobba/gist:3210b2840a540debad47
Tiny component & entities module
var componentsList = {};
function Component(name, func) {
componentsList[name] = func;
}
//Components are created like this:
Component('flying', function(o) {
o.flying = true;
});
@caracal7
caracal7 / LICENSE.txt
Created January 27, 2018 00:29 — forked from Downchuck/LICENSE.txt
DOM micro-DSL
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Charles Pritchard <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@caracal7
caracal7 / demo.js
Created January 27, 2018 08:55 — forked from ooflorent/demo.js
Basic ECS
// Components
// ----------
function KeyboardController() {}
function AIController() {}
function Position(x, y) {
this.x = x || 0;
this.y = y || 0;
}
@caracal7
caracal7 / ECSExampleInES6.js
Created January 27, 2018 09:06 — forked from TheSeamau5/ECSExampleInES6.js
ECS Example in Javascript / ES6
// HELPER FUNCTIONS
const has = (entity, components) => {
const exists = (x) => typeof x !== "undefined";
return components.map((component) => exists(entity[component]))
.reduce((x,y) => x && y);
};
const clone = (object) => {
if (object === null || typeof object !== 'object'){
return object;
@caracal7
caracal7 / actor.js
Created January 27, 2018 09:16 — forked from CrowdHailer/actor.js
Implementing actors in JavaScript.
// Turns out this was not too difficult.
// By using the event loop as a global mail box ordering is even guaranteed for messages between only two actors.
// TODO would like to try and put one actor in a web worker to get some real parallism
// TODO would like to handle errors and have the concept of a deceased actor while a reference to an actor still exists. Probably involves creating an actor system like in Scala. Eurgh.
var actor = {
send: function(message) {
var self = this;
console.log("sending to:", self);
setTimeout(function(){
@caracal7
caracal7 / proxy-reflect.js
Created January 28, 2018 12:11 — forked from scottshane/proxy-reflect.js
Proxy / Reflect Experiment
var targetObject = {
sayHi(){ return `returning show: ${p.show}` },
show: 'family guy',
characters: {
dad: 'peter',
mom: 'lois',
daughter: 'meg',
son: 'chris',
baby: 'stewie',
dog: 'brian'
@caracal7
caracal7 / LICENSE.txt
Created February 1, 2018 20:21 — forked from podefr/LICENSE.txt
Finite State Machine
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Olivier Scherrer
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE