Skip to content

Instantly share code, notes, and snippets.

View jkinkead's full-sized avatar

Jesse Kinkead jkinkead

View GitHub Profile
@jkinkead
jkinkead / webpack.config.js
Created October 18, 2018 23:56
Webpack configuration for Google Cloud Functions
const webpack = require('webpack')
const path = require('path')
const nodeExternals = require('webpack-node-externals')
const StartServerPlugin = require('start-server-webpack-plugin')
module.exports = {
entry: [
'webpack/hot/poll?1000',
'./local/server'
],
watch: true,
@jkinkead
jkinkead / local.js
Created October 18, 2018 23:43
Local Google Cloud Functions server
const http = require('http')
const express = require('express')
const port = 3000
// This function creates an Express app to emulate Google Cloud
// Platform's Cloud Function httpsTrigger[s] then registers all of
// the Cloud Function handlers with the Express app. We'll be passing in
// all of the exports from our index.js file as the "functions" parameter
// below.
const setUpApp = (functions) => {
struct UserLogin {
password: String,
username: String,
}
let loginInfo: UserLogin = getLoginFromEnvironment();
// These variable names must match the struct names for the short syntax.
let UserLogin { username, password } = loginInfo;
// You can rebind explicitly, if you want new names.
let UserLogin { username: myUsername, password: myPassword } = loginInfo;
data class UserLogin(val password: String, val username: String)
val loginInfo: UserLogin = getLoginFromEnvironment()
val (username, password) = loginInfo
System.out.println("Trying to log in with username $username.")
performLogin(username, password)
data class UserLogin(val username: String, val password: String)
val loginInfo: UserLogin = getLoginFromEnvironment()
val (username, password) = loginInfo
System.out.println("Trying to log in with username $username.")
performLogin(username, password)
// Arguments for an execution of 'rm'. Now with sorted flags!
data class RmOptions(val path: String, val force: Boolean, val recursive: Boolean)
val options: RmOptions = getOptions()
// (oops)
val (path, recursive, force) = options
val args = ArrayList<String>()
if (recursive) {
args.append("-r")
data class User(val field0: String, val field1: Int)
val myUser = User("Chip", 15)
val userName = myUser.field0
val userAge = myUser.field1
data class User(val name: String, val age: Int)
val myUser = User("Chip", 15)
// Destructuring myUser into two fields.
val (userName, userAge) = myUser
@jkinkead
jkinkead / pre-commit
Created October 13, 2017 22:05
"Do no harm" pre-commit template.
#!/usr/bin/env bash
# "Do no harm" autoformatter pre-commit script template.
# This example uses gofmt on all .go files.
# Files matching this pattern will be auto-formatted.
FILE_PATTERN='\.go$'
# The tool to check for.
FORMAT_TOOL=gofmt
# Vim swap files.
.*.sw[p-z]
# Emacs backups.
*~
# OS X cache files.
.DS_Store
.Trashes
.Spotlight-V100