Skip to content

Instantly share code, notes, and snippets.

View shamasis's full-sized avatar

Shamasis Bhattacharya shamasis

View GitHub Profile
@shamasis
shamasis / tail-slack.sh
Last active December 28, 2017 06:09
Tail a file and output to slack
#!/bin/bash
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done
@shamasis
shamasis / describe-it.min.js
Last active May 4, 2018 02:58
mocha/jasmine compatible test framework for postman test scripts (in less than 1KB minified)
(typeof tests!=='object')&&(tests={});var
it=((it=function(k,v){it.d.push(k);it.t[it.d]=1;it.b.forEach(it.c);try{v()}catch(e){it.t[it.d]=0;setTimeout&&setTimeout(function(){throw e;})}it.a.forEach(it.c);it.d.pop()}),
it.a=[],it.b=[],it.c=function(x){x()},it.d=[],it.d.toString=function(){return this.join(' ')},
it.t=tests,it.x=function(v){this.v=v},it.xp=it.x.prototype,it.xp.toBe=function(x){(this.v!==x)&&it._()},
it.xp.toNotBe=function(x){(this.v===x)&&it._()},it.xp.toEql=function(x){(this.v!=x)&&it._()},
it.xp.toNotEql=function(x){(this.v==x)&&it._()},it.xp.toBeOk=function(){!this.v&&it._()},
it.xp.toNotBeOk=function(){this.v&&it._()},it),describe=function(k,v){it.d.push(k);v();it.d.pop()},
expect=function(v){return new it.x(v)},beforeEach=it.b.push.bind(it.b),afterEach=it.a.push.bind(it.a);
@shamasis
shamasis / describe-it.js
Last active September 5, 2023 07:12
mocha/jasmine compatible test framework for postman test scripts (in less than 1KB minified)
/**
* @module describe-it
*
* This module defines global variables to provide unit test case runner functions compatible with mocha and jasmine.
* The codebase is written for brevity and facilitate being as lightweight as possible.
*
* The code is intended to be included in Postman Test Sandbox.
*/
/**
@shamasis
shamasis / SlackBootstrap.js
Last active August 29, 2015 21:13
SlackBootstrap for SailsJS
/**
* Bootstrap module for Slack notification on server startup
*
* Expects: config/slack.js
* - enabled
* - organisation
* - key
* - messages.spawn
* - payload
*/
@shamasis
shamasis / ServerStatsBootstrap.js
Created August 26, 2015 22:44
SailsJS bootstrap module to log package version
/**
* ServerStatsBootstrap.js
* Bootstrap module to log server version from package file
*/
module.exports = function (done) {
require('fs').readFile('package.json', function (err, data) {
// exit if error in reading file
if (err) {
sails.log.error('Unable to read package. %s', err);
return done();
@shamasis
shamasis / bootstrap.js
Last active August 26, 2015 22:47
Modular Bootstrap for SailsJS
/**
* Bootstrap
* (sails.config.bootstrap)
*
* An asynchronous bootstrap function that runs before your
* Sails app gets lifted.
*/
module.exports.bootstrap = function (callback) {
// load all modules *Bootstrap.js in bootstrap directory
// and execute async
@shamasis
shamasis / quickargs.js
Last active August 29, 2015 14:17
Quick parsing of CLI arguments
/**
* @example
* var args = require('./quickargs.js')(process.argv);
*/
module.exports = function (argv) {
var args = {}, // object to store all key-value argument extraction
lastarg; // args are split by space, so we keep a track of last key detected
argv && argv.slice && argv.slice(2).forEach(function (item) {
lastarg = /^-/.test(item) ? item.slice(1) : (lastarg && (args[lastarg] = item), undefined);
@shamasis
shamasis / guid-builder.js
Last active August 29, 2015 14:13
UUID (GUID) generation
/**
* Returns unique GUID on every call as per pseudo-number RFC4122 standards.
*
* @type {function}
* @returns {string}
*/
module.exports = (function() {
var E = '',
H = '-',
@shamasis
shamasis / alloc-assoc-elastic-ip.sh
Created December 21, 2014 09:41
Create and allocate AWS Elastic IP at one go using AWS CLI. Replace `$1` with your Instance Id or simply execute this file as a script and pass the Instance Id as the first argument to the script.
aws ec2 associate-address --instance-id $1 --public-ip $(aws ec2 allocate-address --output text --query 'PublicIp')
@shamasis
shamasis / isarray.js
Last active August 29, 2015 14:08
Best JavaScript Array Detection Technique
/**
* Check whether an object is Array or not
* @type Boolean
* @param {object} subject is the variable that is
* tested for Array identity check
*/
var isArray = (function () {
// Use browser's own `isArray` when available
if (Array.isArray) {
return Array.isArray;