Skip to content

Instantly share code, notes, and snippets.

View jba's full-sized avatar

Jonathan Amsterdam jba

View GitHub Profile
@jba
jba / addheader.go
Last active February 9, 2024 17:23
add custom headers to a GCP client
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"cloud.google.com/go/vertexai/genai"
@jba
jba / user.go
Created September 5, 2022 13:09
// https://gitlab.com/yoanyombapro/CubeMicroservices/-/blob/08ad700e385853134c5149155e2681c40db1195c/podinfo/pkg/database/user.go
package database
import (
"context"
"database/sql"
"errors"
"time"
"github.com/jinzhu/gorm"
@jba
jba / tf-apply.out
Created December 8, 2021 12:17
`terraform apply` output for tf GCP forwarding rule bug
2021-12-08T07:10:24.110-0500 [DEBUG] Adding temp file log sink: /tmp/terraform-log674306730
2021-12-08T07:10:24.110-0500 [INFO] Terraform version: 1.0.9
2021-12-08T07:10:24.110-0500 [INFO] Go runtime version: go1.16.4
2021-12-08T07:10:24.110-0500 [INFO] CLI args: []string{"/google/data/rw/users/jb/jba/bin/terraform-1.0.9", "apply", "-var", "dev_client_secret=xxx", "-auto-approve"}
2021-12-08T07:10:24.110-0500 [DEBUG] Attempting to open CLI config file: /usr/local/google/home/jba/.terraformrc
2021-12-08T07:10:24.110-0500 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2021-12-08T07:10:24.110-0500 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2021-12-08T07:10:24.110-0500 [DEBUG] ignoring non-existing provider search directory /usr/local/google/home/jba/.terraform.d/plugins
2021-12-08T07:10:24.110-0500 [DEBUG] ignoring non-existing provider search directory /usr/local/google/home/jba/.local/share/terraform/plugins
2021-12-08T07:10:24.110-0500 [DEBUG] ignoring non-exist

Determining whether two patterns overlap

(This is a more detailed and precise version of https://stackoverflow.com/a/63914397/9459301.)

A pattern is an alternating sequence of literals, which match only themselves, and wildcards, which match zero or more characters. For example, ab*c*de is a pattern with starting literal ab, interior literal c, and ending literal de.

Two patterns p1 and p2 overlap if there is some string that they both match. We can compute whether they overlap in linear time as follows.

// This program demonstrates a serializability violation.
// Before running, start a postgres DB on port 5432, as with
// docker run -d -p 5432:5432 -e LANG=C -e POSTGRES_PASSWORD=pwd postgres:13.2
package main
import (
"context"
"database/sql"
"errors"
API Compatability in Go
26 November 2018
Jonathan Amsterdam
* Goal
Help the developer make an informed choice about how to change the semantic version of their module.
- Incompatible change (major version bump)
package main
import (
"flag"
"fmt"
"log"
"regexp"
"strings"
"time"
// Sample program for OpenCensus tracing in the Cloud Spanner client.
// The database specified by the flags should have two columns,
// Key and Value, both strings.
package main
import (
"flag"
"fmt"
"log"
// Tool to publish messages at intervals, or receive messages.
package main
import (
"flag"
"fmt"
"log"
"os"
"sync/atomic"
"time"
package main
import (
"flag"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
"sync"