Skip to content

Instantly share code, notes, and snippets.

View lestrrat's full-sized avatar

lestrrat lestrrat

View GitHub Profile
# App Engine Standard Go 1.9 migration to Go 1.11
tag:["google-app-engine", "Go"]
Migrating from Go 1.9 to 1.11 in App Engine Standard isn't just a matter of updating Go itself -
it introduces a major update in the runtime itelf. Because of this, you can't just change your
code to work on Go 1.11 and expect it to be deployed properly. You will need to work on a few
more issues.
This article describes the new runtime known as the Google App Engine Standard 2nd Gen,
@lestrrat
lestrrat / update-healthcheck.sh
Created October 30, 2018 04:54
Ever wanted to make health checks for GCP LBs (created from GKE ingress objects) to look at Cloud Endpoint's ESP server's alternate health check port? Well you're in luck, my friend.
#!/bin/bash
set -e
# Script to configure the healthcheck for ESP
# (ESP listens on a separate port from the main port for healthchecks)
SERVICE_NAME="This the name of your service that you proxy your requests to"
ESP_HEALTH_CHECK_PORT_NAME="This is the name of the port that ESP listens for health checks."
ESP_MAIN_PORT_NAME="This is the name of the port that ESP listens for the actual service."
@lestrrat
lestrrat / cleanup.pl
Last active December 12, 2017 02:19
Delete dangling TCP Load Balancers on GCP Created By Kubernetes Services
use strict;
use JSON ();
my $src = qx(gcloud compute forwarding-rules list --format json);
my $json = JSON->new;
my $rules = $json->decode( $src );
for my $rule (@$rules) {
print "forwarding-rule $rule->{name}:\n";
if ($rule->{description} =~ m{kubernetes\.io/service-name}) { # TCP (k8s Service with external address)
my ($target_pool) = ($rule->{target} =~ m{/([^/]+)$});
// Wrap the handler with a context that holds the transaction
func withTx(h http.Handler) http.Handler {
return http.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
tx, err := globalDB.BeginTx(r.Context())
if err != nil {
http.Error(...)
return
}
r = r.WithContext(context.WithTx(r.Context(), tx))
h.ServeHTTP(w, r)
@lestrrat
lestrrat / stages.md
Last active November 5, 2024 14:17
Seven Stages of Becoming a Go Programmer
  • stage 1: You believe you can make Go do object oriented programming. You want to do this by using clever struct embedding.
  • stage 2: You believe goroutines will solve all of your problems. You want to use goroutines for anything and everything that you can, who cares if the code becomes a bit more complicated
  • stage 3: You believe that instead of object oriented programming, interfaces will solve all of your problems. You want to define everything in terms of interfaces
  • stage 4: You believe channels will solve all of your problems. You want to do everything from synchronization, returning values, and flow control using channels.
  • stage 5: You now believe Go is not as powerful as people claim it to be. You feel like you're stripped of all of the nice tools and constructs that other languages provide.
  • stage 6: You realize that stages 1~5 were all just your imagination. You just didn't want to accept the Go way. Everything starts to make sense.
  • stage 7: You are now at peace
use strict;
use feature 'say';
sub is_anagram {
my ($s1, $s2) = @_;
my %chars1;
my %chars2;
for my $c (split //, $s1) {
$chars1{$c}++;
@lestrrat
lestrrat / wc.go
Last active September 25, 2016 05:33
おもしろそうだったので自分もwc書いてみたけど、元のCで書かれたwcをあんまり改良するところがなかった…
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"runtime/pprof"
"sync"
func TestParallelBatch(t *testing.T) {
dir, err := ioutil.TempDir("", "leveldb-test-")
if !assert.NoError(t, err, "ioutil.TempDir should succeed") {
return
}
defer os.RemoveAll(dir)
db, err := leveldb.OpenFile(dir, nil)
if !assert.NoError(t, err, "leveldb.OpenFile should succeed") {
return
@lestrrat
lestrrat / worker.go
Last active September 14, 2024 01:55
package main
import (
"context"
"fmt"
"log"
"math/rand"
"os"
"os/signal"
"sync"