Skip to content

Instantly share code, notes, and snippets.

@kohendrix
kohendrix / docker-compose.yml
Last active March 1, 2019 07:21
node + mysql setup
version: '3'
services:
app:
build:
context: .
dockerfile: ./node/Dockerfile
container_name: node_app
ports:
- '3000:3000'
@kohendrix
kohendrix / index.ejs
Last active February 28, 2019 08:42
Google Sign-in Express + pjs
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel="stylesheet" href="/stylesheets/style.css" />
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="<%= clientIdUrl %>" />
<script>
// called by google client
function onSignIn(googleUser) {
@kohendrix
kohendrix / index.ejs
Created February 28, 2019 08:33
Google Sign-in implementation on html
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="<%= clientIdUrl %>" />
@kohendrix
kohendrix / index.ejs
Created February 28, 2019 08:45
Google Sign-in callback functions
<script>
// called by google client
function onSignIn(googleUser) {
var id_token = googleUser.getAuthResponse().id_token;
// never log these out on a real app
console.log('id_token: ', id_token);
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
@kohendrix
kohendrix / googleApisClient.js
Created February 28, 2019 09:23
Google sign-in OAuth2 sample
import { OAuth2Client } from 'google-auth-library';
const p = console.log;
/**
* this establishes the connection
* @return { OAuth2Client }
*/
function getOAuth2Client() {
return new OAuth2Client('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'REDIRECT_URL');
}
@kohendrix
kohendrix / googleApisClient.js
Created February 28, 2019 09:48
Google sign-in url getter
import { OAuth2Client } from 'google-auth-library';
const p = console.log;
/** APIs Explorer for OAuth2 v1: https://developers.google.com/apis-explorer/#p/oauth2/v1/ **/
const infoUrl = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=JSON';
/**
* information scope needed
* reference: https://developers.google.com/identity/protocols/googlescopes
* check: Google OAuth2 API, v2
*/
@kohendrix
kohendrix / googleApisClient.js
Created February 28, 2019 09:56
google sign-in sample. get data from code given in the redirect url
/**
* get selected fields of userinfo
* @param { string } code
* @return { object }
*/
async function getUserInfoFromCode(code) {
const client = getOAuth2Client();
const data = await client.getToken(code);
client.setCredentials(data.tokens);
const userinfo = await client.request({ url: infoUrl });
@kohendrix
kohendrix / template.test.js
Last active March 12, 2019 02:26
Mocha test template with boilerplate chords
/**
* Mocha Test Template
* refs ================================
* Mocha: https://mochajs.org
* Chai: https://www.chaijs.com
* Chai-As-Promised: https://www.chaijs.com/plugins/chai-as-promised/
* Sinon: https://sinonjs.org
* debug: https://www.npmjs.com/package/debug
*/
import chai from 'chai';
@kohendrix
kohendrix / stringValidator.js
Last active March 27, 2019 05:20
Validator.js wrapper for chaining
/**
* wrapper for Validator.js
* ref:
* https://www.npmjs.com/package/validator
*/
import validator from 'validator';
/**
* error messages
*/
@kohendrix
kohendrix / DynamoClient.ts
Created March 26, 2019 04:08
AWS DynamoDB client for Node.js
import AWS from 'aws-sdk';
import {
DocumentClient,
PutItemInput,
PutItemOutput,
GetItemInput,
QueryInput,
ScanInput,
DeleteItemInput,
DeleteItemOutput,