Skip to content

Instantly share code, notes, and snippets.

View wader's full-sized avatar
🦫

Mattias Wadman wader

🦫
View GitHub Profile
@wader
wader / cat.md
Last active October 15, 2021 10:18
cat(1) golf
cat file.txt
grep '' file.txt
awk '/.*/ { print }' file.txt
dd status=none if=file.txt (GNU dd)
curl file://$PWD/file.txt
jq -rRs . file.txt
ffmpeg -v quiet -f data -i file.txt -map 0:0 -c text -f data -
def _chunk($size):
( range(
( (length / $size) | ceil
| if . == 0 then 1 end
)
) as $i
| .[$i * $size:($i + 1) * $size]
);
@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