Skip to content

Instantly share code, notes, and snippets.

@formula1
formula1 / event.js
Created May 27, 2015 17:10
Simple Event Emitter
function EventEmitter(){
this.events = {};
}
EventEmitter.prototype.on = function(event,fn){
if(!(event in this.events)) this.events[event] = [];
this.events[event].push(fn);
}
EventEmitter.prototype.emit = function(event){
@formula1
formula1 / startup.js
Last active March 26, 2017 19:15
Example
var l = 10;
@formula1
formula1 / .gitignore
Last active October 15, 2015 17:58
Boiler Plate
/node_modules
@formula1
formula1 / db.js
Last active January 25, 2016 05:21 — forked from nsuan/announce.php
Bitstorm Tracker
var fs = require('fs');
/*
* Yeah, this is the database engine. It's pretty bad, uses files to store peers.
* Should be easy to rewrite to use SQL instead.
*
* Yes, sometimes collisions may occur and screw the DB over. It might or might not
* recover by itself.
*/
var DB;
@formula1
formula1 / RegeneratableOptionParser.js
Created January 25, 2016 10:37
__init__ to index
// Would REALLY Like to switch over to commander
var RegeneratableOptionParser;
// import optparse
var optparse = require('./optparse');
module.exports = RegeneratableOptionParser = function(optparse){
self.__regeneratable_options = {}
optparse.OptionParser.__init__(self)
@formula1
formula1 / matcher.js
Created March 4, 2016 09:39
matches a query
var matches,matchObj,matchArray,matchSequence,
allUniquePossible,matchString,matchNumber,curry,passesEnough,equal,not;
module.exports.matches = matches = function(obj,tester){
var tt = typeof tester;
if (tt !== 'object') return equal(obj,tester);
if ('is' in tester){
return tester.is;
var Transform = require('stream').Transform;
var ConfigUtil = require('./config.js');
var MatchUtil = require('./matcher.js');
var KeyEmitter;
module.exports = KeyEmitter = function(){
Transform.call(this,{
readableObjectMode : true,
writableObjectMode : true
});
module.exports = function(){
var date = Date.now();
while(Date.now() - date < 5000);
return 'ok';
}
@formula1
formula1 / .babelrc
Created November 16, 2016 21:22
Inferno Basic Example
{
"presets" : [ "es2015" ],
"plugins" : [ "inferno" ]
}
@formula1
formula1 / readme.md
Created February 7, 2017 19:28
Lesson CRUD

Purpose

Teach Developer how to implement simple reusable components and leaving complex database interdependency and logic to those database models.

Why is it good

There will be bugs in your code, there always is. However, there are many benefits to DRY principles.

  • Not reimplementing logic
  • Not rewriting everything
  • Not cutting and pasting