Skip to content

Instantly share code, notes, and snippets.

View sthawali's full-sized avatar

Shekhar Thawali sthawali

  • Leftshift Technologies
  • pune
View GitHub Profile
@sthawali
sthawali / JavaScriptSafeNavigation.md
Created February 17, 2016 09:29 — forked from d-akara/JavaScriptSafeNavigation.md
JavaScript Safe Navigation

Experimental Safe JavaScript Navigation

Implemented using ES6 Proxies and Symbols

Suggestions for improvements welcome!

const nonNavigableTarget = Symbol();

function safe(target, defaultValue) {
@sthawali
sthawali / apn.push.validity.js
Last active January 19, 2016 12:57
Check push certificate expiration
var forge = require('node-forge');
var fs = require('fs');
var moment = require('moment');
var filename = 'P12_FILE_PATH';
var password = 'PASSWORD';
var p12b64 = fs.readFileSync(filename, { encoding: 'base64' });
var p12Der = forge.util.decode64(p12b64);
var p12Asn1 = forge.asn1.fromDer(p12Der);
@sthawali
sthawali / mongoose-paginator.js
Last active August 29, 2015 14:04
Simple server side pagination module for mongoose
'use strict';
/**
* Paginator Plugin(for mongoose)
*
* The MIT License (MIT)
* Copyright (c) 2014 Shekhar R. Thawali<shekhar@leftshift.io>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@sthawali
sthawali / paginator.js
Last active August 29, 2015 14:04
Simple server side pagination module for mongodb
'use strict';
/**
* Paginator
*
* The MIT License (MIT)
* Copyright (c) 2014 Shekhar R. Thawali<shekhar@leftshift.io>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@sthawali
sthawali / validate.price
Created December 4, 2013 12:46
Validate price in (xx.xx/xxx.xx/xxx.xxx) format. Change the limit for your formats.
var regex = /^\d{0,3}(\.\d{1,2})?$/; // This will validate for (xxx.xx) format.
if(regex.test(PRICE_VALUE)) {
// Right format
} else {
// Wrong format
}
@sthawali
sthawali / parseVideoUrl.js
Created October 7, 2013 11:32
Extract source and video id from Youtube and Vimeo url
/* Extract vido id and source from Youtube and Vimeo
*****************************************************/
function extractVideoUrl(url) {
var vimeoRegEx = /https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/;
var youtubeRegEx = /(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/;
function getId(url, type) {
var match = url.match((type === 'youtube') ? youtubeRegEx : vimeoRegEx);
alert(match);
@sthawali
sthawali / active-log.js
Last active December 23, 2015 10:49
Log everything with winston + express-winston
var express = require('express');
var http = require('http');
var app = express();
var expressWinston = require('express-winston');
var winston = require('winston');
var fs = require('fs');
var app = express();
var server = http.createServer(app);
@sthawali
sthawali / handle-error.js
Last active December 23, 2015 10:19
Handle error globally in express.js app
var express = require('express');
var http = require('http');
var app = express();
app.use(
function handleError(req, res, next) {
var domain = require('domain').create();
res.on('close', function() {
domain.dispose();
$('h1').bind('click', function() {
this.log('clicked!');
}, console);
$('h2').bind('click', {msg: 'clicked!'}, function(e) {
this.log(e.data.msg);
}, console);