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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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