Skip to content

Instantly share code, notes, and snippets.

View lestrrat's full-sized avatar

lestrrat lestrrat

View GitHub Profile
@lestrrat
lestrrat / stages.md
Last active May 18, 2022 02:19
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
// https://github.com/lestrrat-go/jwx/blob/129e8b1d3bc86038ded5b41e8720b120194074f8/examples/jwk_parse_key_example_test.go
package examples_test
import (
"encoding/json"
"fmt"
"os"
"github.com/lestrrat-go/jwx/v2/jwk"
)
// https://github.com/lestrrat-go/jwx/blob/129e8b1d3bc86038ded5b41e8720b120194074f8/examples/jwt_builder_example_test.go
package examples_test
import (
"encoding/json"
"fmt"
"os"
"github.com/lestrrat-go/jwx/v2/jwt"
)
package examples_test
import (
"fmt"
"net/http"
"net/url"
"strings"
"github.com/lestrrat-go/jwx/v2/jwt"
)
package main
import (
"context"
"fmt"
"log"
"math/rand"
"os"
"os/signal"
"sync"
@lestrrat
lestrrat / ripple.pl
Last active September 27, 2021 05:09
"Ripple" shift the contents of an SBV file
#!perl
# perl ripple.pl $ref $delta file.sbv
use strict;
use POSIX qw(floor);
# $ref is the time code (in seconds) where the ripple should start
my $ref = shift @ARGV;
#!/bin/bash
# Installs mariadb in Debian 9 GCP VM, creates self-signed certificates,
# sets up the server config, and restarts the mysql server
set -e
set -x
apt-get update
apt-get install -y mysql-server
lestrrat@finch bench % benchstat -sort -delta stdlib.txt v0.4.2.txt
name old time/op new time/op delta
JWK/Serialization/RSA/PrivateKey/jwk.Parse-8 50.0µs ± 1% 15.8µs ± 8% -68.40% (p=0.008 n=5+5)
JWK/Serialization/RSA/PrivateKey/jwk.ParseString-8 50.4µs ± 1% 18.5µs ±15% -63.23% (p=0.008 n=5+5)
JWK/Serialization/EC/PrivateKey/jwk.Parse-8 15.6µs ± 1% 5.8µs ± 5% -63.11% (p=0.008 n=5+5)
JWK/Serialization/EC/PrivateKey/jwk.ParseString-8 15.9µs ± 3% 5.9µs ± 2% -62.64% (p=0.008 n=5+5)
JWK/Serialization/RSA/PrivateKey/jwk.ParseReader-8 50.9µs ± 1% 19.2µs ± 6% -62.31% (p=0.008 n=5+5)
JWK/Serialization/EC/PrivateKey/jwk.ParseReader-8 15.7µs ± 1% 6.0µs ± 4% -61.50% (p=0.008 n=5+5)
JWS/Serialization/JSON/jws.Parse-8 21.1µs ± 1% 8.3µs ± 2% -60.65% (p=0.008 n=5+5)
JWS/Serialization/JSON/jws.ParseString-8 21.3µs ± 2%
@lestrrat
lestrrat / translation2srt.pl
Last active November 17, 2020 23:23
開始時間/終了時間/英語/日本語 の4つのカラムのTSVファイルから、日本語訳文をSRTファイル形式に整形するツール。1行目にヘッダがある想定。使い方はコメントの中に。
#
# Preparation:
#
# 1. Install perl5, cpanm
# 2. cpanm -L local -n Text::CSV_XS
#
# Execution:
#
# perl script.pl source.tsv
#
@lestrrat
lestrrat / aetail.pl
Created January 25, 2012 01:31
tail -f with AnyEvent (is this correct?)
use strict;
use AnyEvent;
use Fcntl qw(SEEK_SET);
use Linux::Inotify2;
main(@ARGV);
sub main {
my $file = shift or die "no file specified";