Skip to content

Instantly share code, notes, and snippets.

View n1lesh's full-sized avatar
🏠
Working from home

Nilesh Singh n1lesh

🏠
Working from home
View GitHub Profile
@n1lesh
n1lesh / notifcenter.html
Created December 23, 2017 09:06
Firebase Cloud Messaging with Node.js - Notification Center (HTML)
<!DOCTYPE html>
<html>
<head>
<title>Notification Center</title>
<style>
body {
text-align: center;
}
h1 {
@n1lesh
n1lesh / fcm6.js
Created December 23, 2017 09:06
Firebase Cloud Messaging with Node.js - FCM 6
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 December 23, 2017 09:05
Firebase Cloud Messaging with Node.js - FCM 5
const sendToAll = (msg, title, regIdArray, response) => {
const data = {
"data": {
"body": msg,
"title": title
}
}
const folds = regIdArray.length % 1000
@n1lesh
n1lesh / fcm4.js
Created December 23, 2017 09:05
Firebase Cloud Messaging with Node.js - FCM 4
const sendToTopics = (msg, title, topic, response) => {
const data = {
"data": {
"body": msg,
"title": title
}
}
data['to'] = '/topics/' + topic
@n1lesh
n1lesh / fcm3.js
Created December 23, 2017 09:05
Firebase Cloud Messaging with Node.js - FCM 3
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 December 23, 2017 09:04
Firebase Cloud Messaging with Node.js - FCM 2
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 December 23, 2017 09:04
Firebase Cloud Messaging with Node.js - FCM 1
'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 December 22, 2017 21:37
Adding ld+json structured data to AngularJs app Raw - Rich Card Directive
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 December 22, 2017 21:37
Adding ld+json structured data to AngularJs app Raw - Controller Code
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 December 22, 2017 21:36
Adding ld+json structured data to AngularJs app Raw - Apple Site's ld+json data example
/* 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",