Skip to content

Instantly share code, notes, and snippets.

View StevenACoffman's full-sized avatar

Steve Coffman StevenACoffman

View GitHub Profile
@StevenACoffman
StevenACoffman / gokitlogrus.go
Last active March 24, 2023 08:32 — forked from bdimcheff/gokitlogrus.go
gokit -> logrus adapter
package log
import (
"fmt"
gokitlog "github.com/go-kit/kit/log"
"github.com/sirupsen/logrus"
stackdriver "github.com/icco/logrus-stackdriver-formatter"
)
@StevenACoffman
StevenACoffman / echo_zap.go
Created October 26, 2019 23:12 — forked from ndrewnee/echo_zap.go
ZapLogger is an example of echo middleware that logs requests using logger "zap"
package echomw
import (
"time"
"github.com/labstack/echo"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
@StevenACoffman
StevenACoffman / timeout_and_tick.go
Created October 25, 2019 14:46 — forked from ngauthier/timeout_and_tick.go
Golang timeout and tick loop
// keepDoingSomething will keep trying to doSomething() until either
// we get a result from doSomething() or the timeout expires
func keepDoingSomething() (bool, error) {
timeout := time.After(5 * time.Second)
tick := time.Tick(500 * time.Millisecond)
// Keep trying until we're timed out or got a result or got an error
for {
select {
// Got a timeout! fail with a timeout error
case <-timeout:
@StevenACoffman
StevenACoffman / git-fork-workflow.md
Created October 23, 2019 14:18
git-fork-workflow

Git Fork Workflow Tips

From Apache Arrow Git Tips I’m used to working with git merge and this has made life difficult for me when working with Apache Arrow because it doesn’t use a merge model and pull request branches often need to rebased against master and force pushed.

There are numerous ways to work in this model but this article documents the approach I use, based on some guidance I was given on one of my PRs. I’m documenting this for my own benefit but hopefully it helps others too.

Creating a Fork

When you first fork the repo, you need to set up the upstream apache git repo as a remote. I prefer to name this remote apache rather than upstream since it is more explicit, especially if I add other remotes (such as other contributors forks).

@StevenACoffman
StevenACoffman / goGetPrivate.md
Last active November 6, 2025 11:05 — forked from dmitshur/gist:6927554
How to `go get` private repos using SSH key auth instead of password auth.

Set GOPRIVATE to match your github organization

I keep fixing this up, but if it fails for you, check if these are better maintained https://tip.golang.org/cmd/go/#hdr-Configuration_for_downloading_non_public_code and https://golang.org/ref/mod#private-modules.

Cloning the repo using one of the below techniques should work correctly but you may still be getting an unrecognized import error.

As it stands for Go v1.13, I found in the doc that we should use the GOPRIVATE variable like so:

GOPRIVATE=github.com/ORGANISATION_OR_USER_NAME go get -u -f github.com/ORGANISATION_OR_USER_NAME/REPO_NAME

The 'go env -w' command (see 'go help env') can be used to set these variables for future go command invocations.

@StevenACoffman
StevenACoffman / go-sql.md
Last active October 5, 2020 14:18
Go SQL

Database Environments

A schema contains a group of tables. A database contains a group of schemas.

In prod, we use a cloudsql PostgreSQL instance. The reports DB is for prod only. It's presence should be a gatekeeper to prevent destructive teardowns.

Everywhere else, we assume a local PostgreSQL running on port 5432 with two existing databases. The khan_test DB is for integration tests. The khan_dev DB is for local development.

@StevenACoffman
StevenACoffman / GPG_and_GIT.md
Last active March 9, 2024 22:10 — forked from JamesOBenson/Generating a secure SSH Key and commands
SSH Generation and commands for GIT and GPG

GPG and GIT and SSH ... OH MY!

ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C [email protected] -N ''
  • Then you won't be prompted for a passphrase. However, if you did have a passphrase:
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C [email protected] -N 'Really do not use this passphrase'
  • Then you will be prompted to type your passphrase every time you interact with git remote (pull, push, fetch, etc.) This is intolerable.
@StevenACoffman
StevenACoffman / git-auto-sign-commits.sh
Last active March 22, 2025 19:38 — forked from mort3za/git-auto-sign-commits.sh
Auto sign your git commits
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C [email protected] -N ''
# -o : Save the private-key using the new OpenSSH format rather than the PEM format. Actually, this option is implied when you specify the key type as ed25519.
# -a: It’s the numbers of KDF (Key Derivation Function) rounds. Higher numbers result in slower passphrase verification, increasing the resistance to brute-force password cracking should the private-key be stolen.
# -t: Specifies the type of key to create, in our case the Ed25519.
# -f: Specify the filename of the generated key file. If you want it to be discovered automatically by the SSH agent, it must be stored in the default `.ssh` directory within your home directory.
# -C: An option to specify a comment. It’s purely informational and can be anything. But it’s usually filled with <login>@<hostname> who generated the key.
# -N: Provides the new passphrase.
eval "$(ssh-agent -s)"
ssh-add -K ~/.ssh/id_ed25519
@StevenACoffman
StevenACoffman / checkWorktreeIsClean.go
Created August 20, 2019 23:33
Check if git working directory is clean
///usr/bin/env go run "$0" "$@" ; exit "$?"
package main
import (
"fmt"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/format/gitignore"
"io/ioutil"
@StevenACoffman
StevenACoffman / checkIsHeadPushed.go
Created August 20, 2019 19:01
Check if git HEAD pushed to origin/master?
///usr/bin/env go run "$0" "$@" ; exit "$?"
package main
import (
"fmt"
"os"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
)