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 / fcm1.js
Last active May 31, 2023 12:24
Firebase Cloud Messaging with Node.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 / SafeBrowsingManifest.xml
Last active August 28, 2022 23:53
Enable Safe Browsing in WebViews - Android O
<manifest>
<application>
. . .
<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
android:value="true" />
. . .
</application>
</manifest>
@n1lesh
n1lesh / LinearGradientDrawable.java
Last active January 30, 2022 03:57
Android Gradient Toolbar and Statusbar
RelativeLayout layout = (RelativeLayout) findViewById(R.id.rel);
GradientDrawable drawable = new GradientDrawable();
drawable.setColors(new int[] {
Color.parseColor("#FFF6B7"),
Color.parseColor("#F6416C")
});
drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
drawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);
@n1lesh
n1lesh / NodeHTTPs1.js
Last active October 19, 2019 14:32
HTTPs Server with Node.js and Express
var express = require('express');
var app = express();
var fs = require('fs');
@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 / InstanceIdService.java
Created December 18, 2017 08:31
Sample Code for Push Notifications (FCM) on Android - Instance ID Service
package com.mynotificationsapp.android;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
@n1lesh
n1lesh / AndroidManifest.xml
Created June 12, 2017 11:00
Sample Code for Push Notifications (FCM) on Android
<?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"
@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