Skip to content

Instantly share code, notes, and snippets.

lestrrat lestrrat

Block or report user

Report or block lestrrat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:db1e1310efc0d52cae563d2e9130fd91
# 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 Oct 30, 2018
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.
View update-healthcheck.sh
#!/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 Dec 12, 2017
Delete dangling TCP Load Balancers on GCP Created By Kubernetes Services
View cleanup.pl
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{/([^/]+)$});
View handler.go
// 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 Jun 1, 2019
Seven Stages of Becoming a Go Programmer
View stages.md
  • 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
View hoge.pl
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 Sep 25, 2016
おもしろそうだったので自分もwc書いてみたけど、元のCで書かれたwcをあんまり改良するところがなかった…
View wc.go
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"runtime/pprof"
"sync"
View parallel_test.go
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
View worker.go
package main
import (
"context"
"fmt"
"log"
"math/rand"
"os"
"os/signal"
"sync"
You can’t perform that action at this time.