Skip to content

Instantly share code, notes, and snippets.

View wader's full-sized avatar
🦫

Mattias Wadman wader

🦫
View GitHub Profile
@wader
wader / pprof.go
Created August 29, 2021 22:25
pprof
package cli
import (
"log"
"os"
"runtime"
"runtime/pprof"
)
func maybeProfile() func() {
@wader
wader / gist:3467ec5a342a704cd61867054b92e9ec
Created June 26, 2021 07:04
alpine arch in dockerfile
https://github.com/docker-library/golang/blob/f300e60ca19c3b98cfcf01ca112af2ac10104320/1.17-rc/alpine3.14/Dockerfile#L30
apkArch="$(apk --print-arch)"; \
case "$apkArch" in \
'x86_64') \
export GOARCH='amd64' GOOS='linux'; \
;; \
'armhf') \
export GOARCH='arm' GOARM='6' GOOS='linux'; \
;; \
@wader
wader / recover.go
Created May 26, 2021 14:24
go recover runtime error test
package main
import (
"fmt"
"runtime"
)
func a(f func()) {
defer func() {
if rv := recover(); rv != nil {
@wader
wader / Dockerfile
Last active June 30, 2021 12:07
dev build shaka-packager with docker
FROM debian:9.5
# Update, and install basic packages
RUN apt-get update
RUN apt-get install -y build-essential curl git python
# install depot_tools http://www.chromium.org/developers/how-tos/install-depot-tools
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
ENV PATH /depot_tools:$PATH
@wader
wader / csv.jq
Created March 14, 2021 14:46
jq csv and csv kv and range map
def csv: split(",");
def csv_kv: [csv[] | split("=") | {(.[0]): .[1]}] | add;
def obj_to_csv_kv: [to_entries[] | [.key, .value] | join("=")] | join(",");
# TODO: errors?
def csv_range_map:
# "0-2=a,1=b" -> ["a", "b", "a"]
[ csv[]
| split("=")
| .[1] as $c
| .[0]
@wader
wader / gist:6558dfad2c182bb107e9d9b60b2f56aa
Last active August 1, 2021 18:32
golang interesting internals and techniques
go run always exits with error code 1 https://github.com/golang/go/issues/13440
probably the reason it print the error code
-coverpk=./... will load all packages, even non-imported ones, causing init() to run
Default behaviour of signals on linux:
https://github.com/golang/go/blob/master/src/runtime/sigtab_linux_generic.go
@wader
wader / gist:1bb7b303401b2ef8321d3f6da2e6c659
Created March 2, 2021 23:34
github linguest add new language steps
docker run -ti --rm -v "$PWD:$PWD" -w "$PWD" -v /var/run/docker.sock:/var/run/docker.sock ubuntu
apt-get install cmake pkg-config libicu-dev docker.io ruby ruby-dev libz-dev build-essential libssl-dev
gem install bundler
script/bootstrap
script/add-grammar https://github.com/wader/linguist-language-jq
script/update-ids
bundle exec rake samples
bundle exec rake test
# work fine for 9.4 to 13
pg_dump -c -U postgres postgre > db.sql
psql -U postgres < db.sql
@wader
wader / jq.json
Last active February 28, 2021 21:37
vscode jq snippets
{
"debug": {
"prefix": "dd",
"body": "debug |",
"description": "Snippet for debug"
},
"debug variable": {
"prefix": "dv",
"body": "(. as $$c | [\"$${1:var}\", $${1:var}] | debug | $$c) |",
"description": "Snippet for debug variable"
@wader
wader / sharedprefix.go
Created February 22, 2021 16:18
shared prefix go
package sharedprefix
func SharedPrefix(vs []string) string {
if len(vs) == 0 {
return ""
}
l := len(vs[0])
for _, s := range vs[1:] {
if l > len(s) {