Skip to content

Instantly share code, notes, and snippets.

View sivasankars's full-sized avatar

SIVA SANKAR sivasankars

  • India
View GitHub Profile
@sivasankars
sivasankars / app.js
Created January 31, 2020 07:19
Firebase Dynamic Links With REST APIs On Node.js - Create a short link from a long link
const request = require('request');
const API_KEY = 'xxx';
const body = {
'longDynamicLink': 'https://niralar.page.link/?link=http://niralar.com/building-rest-apis-with-swagger-on-node-js/'
}
request({
url: `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${API_KEY}`,
method: 'POST', json: true, body
}, function (error, response) {
@sivasankars
sivasankars / app.js
Created January 31, 2020 07:18
Firebase Dynamic Links With REST APIs On Node.js - Create a short link from a long link
const request = require('request');
const API_KEY = 'xxx';
const body = {
'dynamicLinkInfo': {
'domainUriPrefix': 'https://niralar.page.link',
'link': 'http://niralar.com/building-rest-apis-with-swagger-on-node-js/'
}
}
request({
@sivasankars
sivasankars / server.test.js
Last active December 3, 2019 03:53
Creating and Running Test Cases Using Jest
const server = require('./server.js'); // Import Server/Application
// Start application before running the test case
beforeAll((done) => {
server.events.on('start', () => {
done();
});
});
// Stop application after running the test case
@sivasankars
sivasankars / server.js
Last active August 17, 2019 13:56
Creating Web Server With Routes Using Hapi.js
const Hapi = require('@hapi/hapi');
const users = [
{ id: 1, name: 'Siva' },
{ id: 2, name: 'Sivasankar' },
{ id: 3, name: 'Niralar' }
]
const server = Hapi.server({
port: 3000,
host: 'localhost'
@sivasankars
sivasankars / app.js
Created December 6, 2018 02:46
Print Elements of a Matrix in Diagonal Order
var array = [
[[1], [2], [3], [4]],
[[5], [6], [7], [8]],
[[9], [10], [11], [12]],
[[13], [14], [15], [16]],
[[17], [18], [19], [20]]
];
function printAllDgl(array) {
var i = 0, j = 0, output = [];
@sivasankars
sivasankars / app.js
Created July 8, 2018 04:26
Best Practice of Connecting MongoDB Using Mongoose ODM
var mongoose = require('mongoose');
var express = require('express');
// Connect to MongoDB Using Mongoose ODM
mongoose.connect('mongodb://localhost:27017/integration_test', { useNewUrlParser: true });
// Listen For Mongoose Connection Error
mongoose.connection.on("error", function (err) { console.error('Failed to Connect MongoDB'); });
// Listen For Mongoose Disconnection
const express = require('express');
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
// Fork workers.
@sivasankars
sivasankars / index.php
Last active June 12, 2018 18:08
List Posts From WordPress Using REST API With cURL In PHP (http://niralar.com/list-posts-from-wordpress-using-rest-api-with-curl-in-php/)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="List Posts From WordPress Using REST API With cURL In PHP">
<title>Demo - WordPress REST API</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
@sivasankars
sivasankars / app.js
Created February 17, 2018 04:44
Google URL Shortener
'use strict';
var express = require('express');
var { google } = require('googleapis');
// API keys, Client ID and Client Secret @ https://code.google.com/apis/console
var GAPI = "AIzaSyBheQiEQ_NYpsFugde-jb8hmC7FBAFEVHI";
var CLIENT_ID = "507857393893-tmnp49jq8of3en7m81dqdidedupris8d.apps.googleusercontent.com";
var CLIENT_SECRET = "aLHvXDEV_I_YpAA4Y9tl1tdg";
var REDIRECT_URL = "http://localhost:3000/oauth2callback";
var express = require('express');
var mongoose = require('mongoose');
var gridfs = require('gridfs-stream');
var fs = require('fs');
var db_filename = "demo.jpg";
var local_file = "./gridfs.jpg";
mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true });
mongoose.Promise = global.Promise;