Skip to content

Instantly share code, notes, and snippets.

View shamsher31's full-sized avatar
🎯
Focusing

Shamsher Ansari shamsher31

🎯
Focusing
View GitHub Profile
@shamsher31
shamsher31 / Hapi-file-upload
Last active August 29, 2015 14:17
Hapi-file-upload
// http://www.cronj.com/blog/hapi-file-upload-download/
var hapi = require('hapi');
var fs = require('fs');
// Create a server with a host and port
var server = new hapi.Server();
server.connection({
host: '127.0.0.1',
port: 8000
@shamsher31
shamsher31 / Show Ionic Loading popup on each Angular http request
Last active September 13, 2018 20:14
Show Ionic Loading popup on each Angular http request
// For more details refere http://www.webdeveasy.com/interceptors-in-angularjs-and-useful-examples/
angular.module('MyApp', [])
// Custome Interceptor that will get injected on each HTTP request
// Add $ionicLoading at run time using $injector to avoid circular dependency error
.factory('customeInterceptor',['$timeout','$injector', '$q',function($timeout, $injector, $q) {
var requestInitiated;
@shamsher31
shamsher31 / HAPI-JWT Implementation
Last active August 29, 2015 14:24
HAPI-JWT Implementation
var Hapi = require('hapi'),
boom = require('boom');
// Create a server with a host and port
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
@shamsher31
shamsher31 / NodeJS Send Email using SendGrid
Created July 7, 2015 04:41
NodeJS Send Email using SendGrid
var Promise = require('bluebird'),
nodemailer = Promise.promisifyAll(require('nodemailer')),
sendGridTransport = require('nodemailer-sendgrid-transport');
var options = {
auth: {
api_user: process.env.SENDGRID_USERNAME,
api_key: process.env.SENDGRID_PASSWORD
}
}
@shamsher31
shamsher31 / Javascript UTC time from Timestamp
Created July 8, 2015 04:56
Javascript UTC time from Timestamp
function getUTCTimeFromTimeStamp(timestamp) {
var currentTime = new Date(timestamp),
unixTime = new Date(
currentTime.getUTCFullYear(),
currentTime.getUTCMonth(),
currentTime.getUTCDate(),
currentTime.getUTCHours(),
currentTime.getUTCMinutes(),
currentTime.getUTCSeconds()
@shamsher31
shamsher31 / HapiJS TV logs
Last active August 29, 2015 14:25
HapiJS TV logs
//https://www.npmjs.com/package/tv
var Hapi = require('hapi');
var Tv = require('tv');
// Create a server with a host and port
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
@shamsher31
shamsher31 / Mongodb blog status based on author example
Created July 27, 2015 10:12
Mongodb blog status based on author example
//http://stackoverflow.com/questions/31649223/mongodb-aggregate-blog-post-based-on-status/31649870#31649870
@shamsher31
shamsher31 / Mongodb blog status based on author example
Last active August 29, 2015 14:25
Mongodb blog status based on author example
//http://stackoverflow.com/questions/31649223/mongodb-aggregate-blog-post-based-on-status/31649870#31649870
//Also refer this http://stackoverflow.com/questions/12700836/mongodb-aggregate-query-equivalent-to-postsgresql
How to get the output like this
[{
"_id" : ObjectId('dshe1hhdsa12dashe21dqs'),
"blogId" : 'dhsad78sa6dsa66ds6ds6ds8ds',
"published" : 10,
"approved" : 15,
@shamsher31
shamsher31 / Encrypt and Decrypt using crypto nodejs
Created August 19, 2015 14:13
Encrypt and Decrypt using crypto nodejs
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = '6LehWQcTAAAAADgH-I5WmmkuDFFJ_pMr_866zz17';
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
@shamsher31
shamsher31 / Javascript Closure
Created August 27, 2015 06:13
Javascript Closure
// returns an object that does not itself possess "var a"
// The closure gives indirect access to a, via the public getter and setter.
function f() {
var a = 1;
return {
getA: function() {
return a;
},
setA: function( A ) {