Skip to content

Instantly share code, notes, and snippets.

@sat0yu
sat0yu / code.gs
Last active May 5, 2022 04:21
CreateGithubIssueFromGoogleFormResponse
function onFormSubmit(e) {
const headers = {
outline: "Outline",
expected: "What's the expected result?",
actual: "What's the actual result?",
howToReproduce: "Steps to reproduce the issue",
details: "Additional details",
email: "Email Address",
};
const title = e.namedValues[headers.outline][0];
#!/bin/bash -eux
if [ $# -ne 3 ]; then
echo "./generate.sh USER_NAME CLUSTER_NAME HOSTNAME" 1>&2
exit 1
fi
USER_NAME=$1
CLUSTER_NAME=$2
HOSTNAME=$3
#!/bin/bash -eux
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo"
exit 1
fi
REGISTRIES_YAML_PATH=/etc/rancher/k3s/registries.yaml
if [ -e $REGISTRIES_YAML_PATH ]; then
@sat0yu
sat0yu / memo.sh
Created April 10, 2021 05:12
Openssl
# -e: encryption, -base64 (-a): use base64 encoding/decoding, -pass: `pass:xxx` sets the password `xxx` to encrypt/decrypt, -p: print salt, key, IV
echo "hello" | openssl enc -aes-128-cbc -e -base64 -pass pass:test -p
# salt=FE03CBE926FC4070
# key=FFF339A34C98ED8D8B8843E3F1846104
# iv =EAEAD799A571F360BA1C17B335E2701F
# U2FsdGVkX1/+A8vpJvxAcFEj7ilI/zfrmA3EZ5VQUeY=
# -d: decryption
echo "U2FsdGVkX1/+A8vpJvxAcFEj7ilI/zfrmA3EZ5VQUeY=" | openssl enc -aes-128-cbc -d -base64 -pass pass:test -p
# salt=FE03CBE926FC4070
@sat0yu
sat0yu / minhash.go
Created September 15, 2019 01:26
A MinHash implementation in go
package main
import (
"fmt"
"log"
"math/rand"
"time"
)
const DIM = 26 // |{'a', ..., 'z'}| = 26
#!/bin/bash -eux
if [ $# -ne 3 ]; then
echo "./generate.sh USER_NAME CLUSTER_NAME HOSTNAME" 1>&2
exit 1
fi
USER_NAME=$1
CLUSTER_NAME=$2
HOSTNAME=$3
/*
MariaDB [hoge]> call populate_timedim();
Query OK, 7200 rows affected (8.972 sec)
MariaDB [hoge]> select * from timedim limit 10;
+----+---------------------+
| id | ts |
+----+---------------------+
| 1 | 2020-08-27 08:00:00 |
| 2 | 2020-08-27 08:00:01 |
class ActiveRecordWithConnectionInterceptor < ::GRPC::ServerInterceptor
def request_response(**)
# ref: https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L54-L56
::ActiveRecord::Base.connection_pool.with_connection do
yield
end
end
alias_method :server_streamer, :request_response
alias_method :client_streamer, :request_response
@sat0yu
sat0yu / bloomfilter.go
Created September 23, 2019 16:21
A BloomFilter implementation
package main
import (
"bufio"
"crypto/md5"
"encoding/hex"
"fmt"
"math/big"
"os"
)
@sat0yu
sat0yu / interceptor.go
Created July 7, 2019 02:21
sentry-raven-grpc/interceptor.go
// ErrorCapturer specifies the implementation of a method to capture the given error
type ErrorCapturer interface {
CaptureError(err error, tags map[string]string) string
}
// SentryRavenInterceptor creates an interceptor which catches the errors from each service method and reports them to Sentry
func SentryRavenInterceptor(ec ErrorCapturer) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, _info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
resp, err := handler(ctx, req)
if err != nil {