Skip to content

Instantly share code, notes, and snippets.

View NguyenTungs's full-sized avatar

Nguyen Tung NguyenTungs

View GitHub Profile
@NguyenTungs
NguyenTungs / app.js
Created June 25, 2016 08:49 — forked from DanisHack/app.js
Rendering angularjs app using ejs from node server and how to use a JS variable which is passed to ejs template for angular app.
//@server in express js file
var data = {};
data.title = "My First APP";
data.arr=[{x:1, y:1}, {x:2, y:2}, {x:3, y:4}];
res.render('/ejsFile', data);
@NguyenTungs
NguyenTungs / html5-video-streamer.js
Created April 24, 2017 07:05 — forked from lleo/html5-video-streamer.js
This is an enhancement to Gist#1993068 https://gist.github.com/paolorossi/1993068 . I found what was needed to demonstrate a functioning video stream was a HTML file with a <video> tag pointing to the streamer.
#!/usr/bin/env node
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
* Modified from https://gist.github.com/paolorossi/1993068
*/
var http = require('http')
, fs = require('fs')
, util = require('util')
@NguyenTungs
NguyenTungs / aws.sns.js
Created December 22, 2017 04:16 — forked from anshul313/aws.sns.js
AWS SNS ( Simple Push Notification ) using Node.js
var AWS = require('aws-sdk');
AWS.config.update({accessKeyId: config.AWSAccessKeyId, secretAccessKey: config.AWSSecretKey,{region: config.AWSRegion}});
var sns = AWS.SNS();
var params ={
Name:"test",
Platform:"GCM",//or APNS (Apple ) or ADM (Amazon)
Attributes:{ // required
@NguyenTungs
NguyenTungs / notify-awssns2fcm.js
Created December 22, 2017 06:57 — forked from shinoda-ak/notify-awssns2fcm.js
Notify FCM for Android via AWS SNS
// Notify Target ARN for Android device
'use strict';
const AWS = require('aws-sdk');
const sns = new AWS.SNS({
apiVersion: '2010-03-31',
region: 'MY_REGION'
});
if (process.argv.length < 3) {
console.log('Usage: node notify.js ENDPOINT_ARN');
process.exit();
@NguyenTungs
NguyenTungs / app.js
Created December 22, 2017 07:14 — forked from tatsuyaueda/app.js
Lambda to AWS SNS Linphone Push Notification
console.log('Loading function');
var aws = require('aws-sdk');
var sns = new aws.SNS({
apiVersion: '2010-03-31',
region: 'us-east-1'
});
exports.handler = function(params, context) {
@NguyenTungs
NguyenTungs / firebase_detect_data.js
Created March 15, 2018 06:49 — forked from anantn/firebase_detect_data.js
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
@NguyenTungs
NguyenTungs / firebase_detect_data.js
Created March 15, 2018 06:49 — forked from anantn/firebase_detect_data.js
Firebase: Detecting if data exists. This snippet detects if a user ID is already taken
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
const people = Array.from(document.querySelectorAll('.people p'));
const names = peopleArray.map(person => person.textContent);
// ---------------------------------------------------------------
const names = Array.from(document.querySelectorAll('.people p'), person => {
return person.textContent
});
@NguyenTungs
NguyenTungs / base64-image-upload.js
Created June 12, 2018 08:57 — forked from madhums/base64-image-upload.js
save base64 encoded image
/*
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674
*/
var fs = require('fs');
// string generated by canvas.toDataURL()
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0"
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO"
+ "3gAAAABJRU5ErkJggg==";
// strip off the data: url prefix to get just the base64-encoded bytes
@NguyenTungs
NguyenTungs / index.js
Created August 9, 2018 04:29 — forked from JonathanMH/index.js
JSON Web Token Tutorial: Express
// file: index.js
var _ = require("lodash");
var express = require("express");
var bodyParser = require("body-parser");
var jwt = require('jsonwebtoken');
var passport = require("passport");
var passportJWT = require("passport-jwt");