Skip to content

Instantly share code, notes, and snippets.

@shimdh
shimdh / forEach.js
Last active August 29, 2015 13:58
Fast forEach method than native method in Node.js
"use strict";
module.exports = function(obj, func, context) {
var kIndex,
length;
for (kIndex = 0, length = obj.length; kIndex < length; kIndex++) {
func.call(context, obj[kIndex], kIndex, obj);
}
};
@shimdh
shimdh / allExist.js
Created April 14, 2014 05:43
checking all keys exist in collection.
"use strict";
var _ = require('underscore');
require('underscore-contrib');
module.exports = function(collection) {
return _.every(_.map(collection, function(key) {
return _.exists(key);
}));
};
@shimdh
shimdh / btree.js
Created April 17, 2014 00:51
Modified for node.js from behavior tree for browser.
"use strict";
var Base = function() {
// dummy
};
Base.extend = function(_instance, _static) { // subclass
var extend = Base.prototype.extend;
// build the prototype
Base._prototyping = true;
var proto = new this;
@shimdh
shimdh / base.js
Created April 18, 2014 01:21
base module in behavior tree for node.js
"use strict";
var Base = function() {
// dummy
};
Base.extend = function(_instance, _static) { // subclass
var extend = Base.prototype.extend;
// build the prototype
Base._prototyping = true;
var proto = new this;
@shimdh
shimdh / btree.js
Created April 18, 2014 01:24
btree module in behavior tree for node.js
"use strict";
var Base = require('./base');
var countUnnamed = 0,
BehaviorTree;
BehaviorTree = Base.extend({
constructor: function(config) {
countUnnamed += 1;
this.title = config.title || 'btree' + (countUnnamed);
@shimdh
shimdh / extendObject.js
Created April 21, 2014 07:57
extended winston logger in node.js
"use strict";
/**
* Created by zizisky on 14. 4. 20.
*/
Object.defineProperty(global, '__stack', {
get: function() {
var orig = Error.prepareStackTrace;
@shimdh
shimdh / logger.js
Created April 21, 2014 08:01
example source using extendObject.js
"use strict";
require('./extendObject'); // for __stack, __line, __function
var fs = require('fs');
var winston = require('winston');
var moment = require('moment');
var util = require('util');
@shimdh
shimdh / debugWorker.js
Created April 22, 2014 12:15
example source for debugging workers in node.js using cluster.
var cluster = require('cluster');
var http = require('http');
if (cluster.isMaster) {
var debug = process.execArgv.indexOf('--debug') !== -1;
cluster.setupMaster({
execArgv: process.execArgv.filter(function(s) { return s !== '--debug' })
});
for (var i = 0; i < 2; ++i) {
if (debug) cluster.settings.execArgv.push('--debug=' + (5859 + i));
@shimdh
shimdh / choose_restaurant.js
Created February 6, 2015 03:35
회사 근처 식당 고르기
var _ = require('underscore'),
restaurantMap = {
moo: "무명식당",
soon: "순대국",
book: "북어국",
mook: "어묵",
seol: "설렁탕",
kim: "김치찌게",
cheol: "철판목장",
don: "돈까스",
@shimdh
shimdh / test.html
Last active September 12, 2016 09:20
<section data-background-transition='zoom' data-transition='concave' data-background='http://ryanjarvinen.com/presentations/shared/img/broadcast_reveal_dark.png' data-state='blackout'>
<h2>Gist-Powered</h2>
<h1>Reveal.js</h1>
<h2>Slideshow Presentations</h2>
<p class='fragment'><small><a class='fragment' href='http://github.com/ryanj/gist-reveal'>github.com/ryanj/gist-reveal</a>
<br/> <a class='fragment' href='https://registry.hub.docker.com/u/ryanj/gist-reveal/'>registry.hub.docker.com/u/ryanj/gist-reveal</a></small></p>
</section>
<section data-background-transition='zoom' data-transition='linear'>
<h2>Try it out!</h2>
<p>Create your own deck by forking a copy of <a href='https://gist.github.com/ryanj/af84d40e58c5c2a908dd'>this github gist</a>: <br /><a href='https://gist.github.com/ryanj/af84d40e58c5c2a908dd'>https://gist.github.com/ryanj/af84d40e58c5c2a908dd</a></p>