Skip to content

Instantly share code, notes, and snippets.

View pvenkatakrishnan's full-sized avatar

Poornima Venkat pvenkatakrishnan

View GitHub Profile
@pvenkatakrishnan
pvenkatakrishnan / 0_reuse_code.js
Last active August 29, 2015 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@pvenkatakrishnan
pvenkatakrishnan / gist:07e82da97aa43ab6397f
Last active August 29, 2015 14:18
Using middleware config to define environment specific routes in krakenjs apps.

Defining router middleware

//in path/to/controller
var express = require('express');
var router = express.Router();

router.get('/login', require('path/to/loginMiddleware'));
router.post('/login', require('path/to/loginPostMiddleware'));
router.get('/some/other/route', require('path/to/otherRouteMiddleware'));
  1. Cherry picking args to invoke can lose the this context if it were a class instance.
//the pluginSpec from the instrument module
var plugin = {
name: 'aPLugin',
spec: {
'onTransport': {
'clients' : 'someClient' /*or*/ ['clienta', 'clientb', 'clientc' ...] /*or * if none specified */,
'action': 'exec:./doSomething'
},
'onStats':
{

Ability to :

  1. set up a logger before lifecycle events of a kraken app - like when requiring some utility files, talking to services outside of app startup events.
  2. ability to add category for a logger in addition to tagging them.
  3. maybe even add capability based on specific labels on logging events ? unsure if we need multiple levels of filtering enabled
@pvenkatakrishnan
pvenkatakrishnan / javascriptOptimization.md
Last active August 29, 2015 14:04
Optimizing javascript for v8
  • Small functions < 30 lines
  • Monomorphic (preferable same type arguments)
  • Dont leak 'arguments' or dont pass it around
  • While working with modifying big arrays, better to for loop through it than create new arrays to modify it (apparently iterating is much faster than memory allcocation time)

Keybase proof

I hereby claim:

  • I am pvenkatakrishnan on github.
  • I am pvenkatakrishnan (https://keybase.io/pvenkatakrishnan) on keybase.
  • I have a public key whose fingerprint is E132 0585 11D8 B8B3 A464 B889 FD38 BC72 3297 F41D

To claim this, I am signing this object:

@pvenkatakrishnan
pvenkatakrishnan / gist:b1cae982a813c8b29953
Last active August 29, 2015 13:58
Proposal 1: For config in kraken
// make a config object use a confit factory in order to merge two configs
exports.create = function create(options) {
var deferred, protocols, baseFactory, appFactory;
deferred = q.defer();
protocols = createHandlers(options);
//create a baseFactory
baseFactory = confit({ basedir: path.join(path.dirname(__dirname), 'config'), protocols: protocols });
@pvenkatakrishnan
pvenkatakrishnan / gist:16bc07eb282bfebf1087
Created April 7, 2014 19:10
Config in kraken / confit - Proposal 1
function generateConfig(baseDir, protocols, overrides) {
var deferred, factory;
deferred = q.defer();
factory = confit({ basedir: baseDir, protocols: protocols });
overrides.forEach(function(entry) {
factory.override(entry);
});
factory.create(function (err, config) {
var ovride;
//the rule evaluation function is determined by properties: api || (module & api)
//the arguments passed to the api will be (req,rules)
//where rules is the property *rules* in ruleSet
//if just api is set, then rule engine would invoke that function with arguments assuming it is accessible in the namespace
//if module + api is set, then rule engine would require that module and invoke speced api on it.
//if neither module nor api is set, then the rule engine will try to evaluate on locals
//the rule implementation should return true/false
//rules will be evaluated with a switch case mentality. WHichever evaluates to truthy first will win