Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tusharmath's full-sized avatar
😑
Imploding

Tushar Mathur tusharmath

😑
Imploding
View GitHub Profile
@tusharmath
tusharmath / view_architect.js
Last active August 29, 2015 13:57
What is the best approach to setup this view architecture
socket.on('message', function(data) {
//ListView needs to be updated based on the data and the current selected tab
if (user_current_tab === 'special_tab_1') {
take_action_for_special_tab_1(data);
} else if (user_current_tab === 'special_tab_2') {
@tusharmath
tusharmath / scheduler.coffee
Last active August 29, 2015 13:58
A solution to resolve awfully customized event scheduling
class IEvent
constructor: ->
@_rules = []
set_description: (@description) ->
is_it_on: (date) ->
sorted_rules = @_rules
for rule in sorted_rules
if rule.execute date is yes
@tusharmath
tusharmath / gist:067721712be055d6c318
Last active August 29, 2015 14:17
Log stack with a marker in nodejs
global.TimeMarker = {
current: process.uptime(),
start: function () {
this.current = process.uptime();
},
mark: function () {
e = new Error()
console.log((process.uptime() - this.current) + 's', e.stack.split('\n')
.slice(2, 3)[0].replace(/ *at/, ''));
this.start();
@tusharmath
tusharmath / ioc.js
Created April 7, 2015 15:30
Simple IOC pattern for Javascript
"use strict";
var should = require('chai').should();
var _bind = Function.prototype.bind;
var _each = function (arr, callback, ctx) {
for (var i = 0; i < arr.length; i++) {
callback.call(ctx, arr[i]);
}
};
var _find = function (arr, callback, ctx) {
@tusharmath
tusharmath / chain.coffee
Created April 20, 2015 16:15
Chaining API
Q = require 'q'
chai = require 'chai'
.should()
chain = (proto) ->
obj =
_value: null
value: -> @_value
for k, v of proto
obj[k] = chain._actionCreate proto, obj, k, v
obj
@tusharmath
tusharmath / provision.sh
Last active August 29, 2015 14:20
NODE Provision (UBUNTU)
### HOW TO USE
### curl -L PATH | sh
# Package Install
sudo apt-get install mosh
# Install via CURL
# Oh My ZSH
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
sudo chsh -s /bin/zsh
@tusharmath
tusharmath / MockFileServer.js
Created July 29, 2015 07:11
Dynamically create a downloadable file for test purposes
"use strict";
var express = require('express'),
app = express(),
CHAR = '*',
port = 3000;
var defer = Promise.defer();
app.get('/chunk/:size.txt', function (req, res) {
var count = 0,
size = parseInt(req.params.size);
@tusharmath
tusharmath / Performance.coffee
Last active December 21, 2015 07:29
Working performance comparison between typed arrays and simple array
operatorInt = (count, items) ->
i=0
start = (new Date).getTime()
while(i++ != count)
items[0] = 1000
return (new Date).getTime() - start
operatorSimple = (count, items) ->
'use strict';
function getDistinctObjArray(arr) {
var distinctArr = arr.filter(function(el) {
var isDup = el.inArray;
el.inArray = true;
return !isDup;
});
distinctArr.forEach(function(el) {
delete el.inArray;
@tusharmath
tusharmath / esnextbin.md
Last active April 30, 2016 14:12
esnextbin sketch