Skip to content

Instantly share code, notes, and snippets.

View tsavola's full-sized avatar
💭

Timo Savola tsavola

💭
View GitHub Profile
@tsavola
tsavola / black
Created June 22, 2021 10:34
Data URI for black page
data:text/html,<link rel=icon href=data:image/x-icon,><style>*{background:black}<body>
@tsavola
tsavola / commit.md
Last active April 29, 2021 11:30
Git commit subject line conventions

Conventions for structuring Git commit subject line

Follow Git best practices: use imperative mood, and try to limit it to 50 characters or so.

Structure

Instead of a simple sentence, prefer to use a Linux-style component prefix:

<name>: <comment>
@tsavola
tsavola / golintapi-pre-commit-hook.sh
Last active September 23, 2020 13:57
Git pre-commit hook script which runs golintapi
#!/bin/sh
#
# Installation instructions:
# - go get golang.org/x/lint/golint
# - go get github.com/tsavola/golintapi
# - Copy this script to your local Git repository as .git/hooks/pre-commit
# - chmod +x .git/hooks/pre-commit
#
# Note: this script doesn't abort the commit, just displays warnings.
@tsavola
tsavola / TODO.go
Created August 27, 2018 16:57
TODO() which prints the source code location
//go:noinline
func TODO(...interface{}) {
_todo()
// panic("TODO")
}
//go:noinline
func _todo() {
funcName := "<unknown function>"
fileName := "<unknown file>"
@tsavola
tsavola / base64url.js
Created April 7, 2018 11:11
JavaScript (ES6) oneliner for URL-safe base-64 of arraybuffer contents.
btoa(String.fromCharCode(...new Uint8Array(data))).replace(/\+/g, "-").replace(/\//g, "_")
@tsavola
tsavola / sha384base64url.py
Created April 3, 2018 11:41
Python 2/3 oneliner for printing an URL-safe base-64 SHA-384 digest of file contents.
import base64, hashlib, sys; h = hashlib.new("sha384"); h.update(open(sys.argv[1], "rb").read()); print(base64.urlsafe_b64encode(h.digest()).decode())
import functools
class CheckBool:
def __init__(self, value):
assert isinstance(value, bool)
self._value = value
self._checked = False
.text
.file "llvm-link"
.hidden main # -- Begin function main
.globl main
.type main,@function
main: # @main
.result i32
.local i32
# BB#0:
i32.const $push6=, 0
@tsavola
tsavola / tlscontext.go
Created June 8, 2016 21:29
tls.DialContext
package main
import (
"context"
"crypto/tls"
"net"
"time"
)
func dialContextWithDialer(ctx context.Context, dialer *net.Dialer, network, addr string, config *tls.Config) (*tls.Conn, error) {
@tsavola
tsavola / connpair.go
Created April 1, 2016 00:38
Like socketpair, but for Golang, and TCP instead of Unix sockets
package connpair
import (
"net"
)
func ConnPair() (serverConn, clientConn net.Conn, err error) {
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
return