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 / 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 / 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",
@n1lesh
n1lesh / MessageReceiver.java
Created December 18, 2017 08:33
Sample Code for Push Notifications (FCM) on Android - Message Receiver
package com.mynotificationsapp.android;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
@n1lesh
n1lesh / SampleCardView.java
Created December 18, 2017 15:01
Android CardView Sample - Java Raw
CardView cardView = (CardView) findViewById(R.id.cardView);
cardView.setUseCompatPadding(true);
cardView.setContentPadding(30, 30, 30, 0);
cardView.setPreventCornerOverlap(true);
cardView.setCardBackgroundColor(Color.WHITE);
cardView.setCardElevation(2.1f);
cardView.setRadius(0);
cardView.setMaxCardElevation(3f);
@n1lesh
n1lesh / SampleCardView.xml
Created December 18, 2017 15:02
Android CardView Sample - XML
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="250dp"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="0dp"
app:cardMaxElevation="1dp"
app:cardElevation="0.7dp"
app:contentPadding="10dp"
app:contentPaddingBottom="0dp"
app:cardPreventCornerOverlap="true"
@n1lesh
n1lesh / AndroidManifest.xml
Created December 18, 2017 08:30
Sample Code for Push Notifications (FCM) on Android - Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mynotificationsapp.android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"