Skip to content

Instantly share code, notes, and snippets.

View thoughtspeed7's full-sized avatar

Raj Chaudhary thoughtspeed7

View GitHub Profile
@thoughtspeed7
thoughtspeed7 / circle.yml
Created January 3, 2018 23:08
Example YML file for Continuous Integration (CI) and Delivery (CD) for Google Cloud Functions (GCF) using CircleCI
# om namah shivay
machine:
node:
# current node version running in cloud functions as of 02 Jan 2018. see https://cloud.google.com/functions/docs/writing
version: 6.11.5
dependencies:
pre:
# see https://cloud.google.com/sdk/gcloud/reference
- sudo /opt/google-cloud-sdk/bin/gcloud components update --quiet
@thoughtspeed7
thoughtspeed7 / x-hub-signature-verification.js
Created January 5, 2018 13:27
X-Hub-Signature Verification on Google Cloud Functions for Facebook Graph API Webhooks
// om namah shivay
// environment variables
const FB_APP_SECRET = 'your facebook app secret';
// requires
const crypto = require('crypto');
const verifyXHubSignature = req => {
const digest = crypto
@thoughtspeed7
thoughtspeed7 / index.js
Created January 27, 2018 21:12
Google Cloud Functions Best Practices - Using Runtime Configurator to Manage Config Variables
// om namah shivay
// run gcloud beta functions deploy gcf-runtime-configurator --entry-point start --trigger-http
// to deploy this function to gcf using the gcloud tool
const start = (req, res) => {
let html;
if (!global.config) {
loadConfig()
.then(result => {
@thoughtspeed7
thoughtspeed7 / config.json
Last active May 28, 2020 15:10
Node.js Best Practices - Smarter Ways to Manage Config Files and Variables
{
"development": {
"config_id": "development",
"app_name": "my app",
"app_desc": "my app desc",
"node_port": 3000,
"json_indentation": 4,
"database": "my-app-db-dev"
},
"testing": {
@thoughtspeed7
thoughtspeed7 / config.js
Last active November 14, 2022 09:15
Node.js Best Practices - Smarter Ways to Manage Config Files and Variables
// om namah shivay
// requires
const _ = require('lodash');
// module variables
const config = require('./config.json');
const defaultConfig = config.development;
const environment = process.env.NODE_ENV || 'development';
const environmentConfig = config[environment];
@thoughtspeed7
thoughtspeed7 / server.js
Last active March 24, 2018 08:59
Node.js Best Practices - Smarter Ways to Manage Config Files and Variables
// om namah shivay
// requires
const express = require('express');
// environment variables
process.env.NODE_ENV = 'development';
// uncomment below line to test this code against staging environment
// process.env.NODE_ENV = 'staging';
@thoughtspeed7
thoughtspeed7 / vs-code-user-snippets.js
Created March 26, 2018 12:50
Visual Studio Code User Snippets for Node.js
{
/*
// Place your snippets for JavaScript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
@thoughtspeed7
thoughtspeed7 / cloudbuild.yaml
Created March 28, 2018 11:58
Using Container Builder with Cloud Key Management Service (KMS) on Google Cloud Platform
# om namah shivay
steps:
# decrypt root/secrets/cloud-datastore.json
- name: gcr.io/cloud-builders/gcloud
args:
- kms
- decrypt
- --location=global
@thoughtspeed7
thoughtspeed7 / common.js
Created April 23, 2018 11:20
Reusing Mongoose Schema
// om namah shivay
const mongoose = require('mongoose');
const mobile = {
country_code: String,
number: String
};
module.exports = {
@thoughtspeed7
thoughtspeed7 / user.js
Created April 23, 2018 11:21
Reusing Mongoose Schema
// om namah shivay
const mongoose = require('mongoose');
const common = require('./common');
const user_schema = new mongoose.Schema({
_id: mongoose.Schema.ObjectId,
first_name: String,
last_name: String,
mobile: common.mobile,