Skip to content

Instantly share code, notes, and snippets.

Nilesh Singh n1lesh

Block or report user

Report or block n1lesh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@n1lesh
n1lesh / notifcenter.html
Created Dec 23, 2017
Firebase Cloud Messaging with Node.js - Notification Center (HTML)
View notifcenter.html
<!DOCTYPE html>
<html>
<head>
<title>Notification Center</title>
<style>
body {
text-align: center;
}
h1 {
@n1lesh
n1lesh / fcm6.js
Created Dec 23, 2017
Firebase Cloud Messaging with Node.js - FCM 6
View fcm6.js
app.post('/notify', (req, res) => {
let msg = req.body.message,
title = req.body.title,
type = req.body.type,
topic = req.body.topic
if (type === 'topic') {
sendToTopics(msg, title, topic, res)
} else {
@n1lesh
n1lesh / fcm5.js
Created Dec 23, 2017
Firebase Cloud Messaging with Node.js - FCM 5
View fcm5.js
const sendToAll = (msg, title, regIdArray, response) => {
const data = {
"data": {
"body": msg,
"title": title
}
}
const folds = regIdArray.length % 1000
@n1lesh
n1lesh / fcm4.js
Created Dec 23, 2017
Firebase Cloud Messaging with Node.js - FCM 4
View fcm4.js
const sendToTopics = (msg, title, topic, response) => {
const data = {
"data": {
"body": msg,
"title": title
}
}
data['to'] = '/topics/' + topic
@n1lesh
n1lesh / fcm3.js
Created Dec 23, 2017
Firebase Cloud Messaging with Node.js - FCM 3
View fcm3.js
const sendNotifications = (data) => {
const dataString = JSON.stringify(data)
const headers = {
'Authorization': 'key=<your firebase legacy server key>',
'Content-Type': 'application/json',
'Content-Length': dataString.length
}
@n1lesh
n1lesh / fcm2.js
Created Dec 23, 2017
Firebase Cloud Messaging with Node.js - FCM 2
View fcm2.js
app.get('/notifications', (req, res) => {
res.sendFile(__dirname + '/notifcenter.html')
})
app.post('/store', (req, res) => {
MongoClient.connect(url, (err, db) => {
if (err) throw err
else {
db.collection('tokens').insertOne(req.body, (err, body) => {
@n1lesh
n1lesh / fcm1.js
Created Dec 23, 2017
Firebase Cloud Messaging with Node.js - FCM 1
View fcm1.js
'use strict'
const app = require('express')(),
request = require('request'),
mongo = require('mongodb'),
bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: false
@n1lesh
n1lesh / RichCardDirective.js
Created Dec 22, 2017
Adding ld+json structured data to AngularJs app Raw - Rich Card Directive
View RichCardDirective.js
var app = angular.module('home', []);
app.directive('richcard', ['$sce', '$filter', function ($sce, $filter) {
return {
restrict: 'EA',
link: function (scope, element) {
scope.$watch('ld', function (val) {
var val = $sce.trustAsHtml($filter('json')(val));
element[0].outerHTML = '<script type="application/ld+json">'+ val + '</script>'
});
@n1lesh
n1lesh / Controller.js
Created Dec 22, 2017
Adding ld+json structured data to AngularJs app Raw - Controller Code
View Controller.js
app.controller('homeController', ['$scope', function ($scope) {
$scope.$root.ld = {
"@context": "http://schema.org/",
"@type": "WebSite",
"name": 'My Wonderful Site',
"image": "https://mywonderfulsite.com/logo.png",
"description": 'We have the best content in the world',
"url": 'https://mywonderfulsite.com/'
}
@n1lesh
n1lesh / AppleLdJsonExample.js
Created Dec 22, 2017
Adding ld+json structured data to AngularJs app Raw - Apple Site's ld+json data example
View AppleLdJsonExample.js
/* visit www.apple.com and look at
the source code to find it.
*/
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@id": "https://www.apple.com/#organization",
"@type": "Organization",
"name": "Apple",
You can’t perform that action at this time.