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 / Send HTTP request from Image src tag
Created September 10, 2015 11:05
Send HTTP request from Image src tag
.directive('httpSrc', [
'$http', function ($http) {
var directive = {
link: link,
restrict: 'A'
};
return directive;
function link(scope, element, attrs) {
var requestConfig = {
@shamsher31
shamsher31 / Angular Cache Service
Created September 9, 2015 06:28
Angular Cache Service
angular
.module( 'common.cache', [] )
.factory( 'CacheService', CacheService );
function CacheService(){
var service = {};
service.cache = {};
@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 ) {
@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 / 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 / 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 / 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 / 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 / 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 / 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
});