Skip to content

Instantly share code, notes, and snippets.

View jkinkead's full-sized avatar

Jesse Kinkead jkinkead

View GitHub Profile
@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
data class User(val name: String, val age: Int)
val myUser = User("Chip", 15)
// Destructuring myUser into two fields.
val (userName, userAge) = myUser
data class User(val field0: String, val field1: Int)
val myUser = User("Chip", 15)
val userName = myUser.field0
val userAge = myUser.field1
// 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 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)
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)
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;
@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) => {
@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 19, 2018 00:01
Hot reload configuration
// Save the initial app so we can remove it from the server when
// there are Webpack Hot Module Reload updates.
let currentApp = initialApp
if (module.hot) {
module.hot.accept('../index.js', () => {
// Create a new Express app with the updated Cloud Function
// handlers.
const newApp = setUpApp(require('../index.js'))
// Remove the old Express app.