Skip to content

Instantly share code, notes, and snippets.

View sgaurav's full-sized avatar

Gaurav Singh sgaurav

View GitHub Profile
@sgaurav
sgaurav / settle-felony-charges.js
Last active September 19, 2016 05:25
Sending personal responses through FB Messenger bot
app.post('/webhook/', receiveMessage);
function receiveMessage(req, res, next){
var message_instances = req.body.entry[0].messaging;
message_instances.forEach(function(instance){
var sender = instance.sender.id;
if(instance.message && instance.message.text) {
fetchUserProfileAndReply(sender, conf.PROFILE_TOKEN);
}
});
@sgaurav
sgaurav / mobile_operator_circle.json
Last active February 28, 2016 18:07
Maps first four/five digits of user mobile number to corresponding operator and circle.
{
"7026": {
"operator": "IDEA",
"circle": "KARNATAKA"
},
"7036": {
"operator": "IDEA",
"circle": "ANDHRA PRADESH"
},
"7046": {
function serialize(data) {
return Object.keys(data).map(function (keyName) {
return encodeURIComponent(keyName) + '=' + encodeURIComponent(data[keyName])
}).join('&');
}
@sgaurav
sgaurav / gist:d8aa7850fcdaf3319711
Created October 29, 2014 07:24
Javascript method to detect browser without using UA String
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
var isFirefox = typeof InstallTrigger !== 'undefined';
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
var isChrome = !!window.chrome && !this.isOpera;
var isIE = false || !!document.documentMode;