Skip to content

Instantly share code, notes, and snippets.

@daniellowtw
daniellowtw / gist:23b5a7017ea29decb20ea3a6d474eba0
Created June 16, 2022 13:57
Unsafe variable capture in loop
func Test(t *testing.T) {
a := map[int]int{
}
var b sync.Map
for i := 0; i < 2000; i++ {
a[i] = i
}
var wg sync.WaitGroup
wg.Add(2000)
package main
import (
"reflect"
"testing"
"github.com/aws/aws-sdk-go/aws/request"
)
func BenchmarkFooF(b *testing.B) {
@daniellowtw
daniellowtw / go_cpu_memory_profiling_benchmarks.sh
Created April 27, 2022 13:19 — forked from arsham/go_cpu_memory_profiling_benchmarks.sh
Go cpu and memory profiling benchmarks. #golang #benchmark
go test -run=. -bench=. -benchtime=5s -count 5 -benchmem -cpuprofile=cpu.out -memprofile=mem.out -trace=trace.out ./package | tee bench.txt
go tool pprof -http :8080 cpu.out
go tool pprof -http :8081 mem.out
go tool trace trace.out
go tool pprof $FILENAME.test cpu.out
# (pprof) list <func name>
# go get -u golang.org/x/perf/cmd/benchstat
benchstat bench.txt
@daniellowtw
daniellowtw / main_test.go
Created September 14, 2021 16:05
String append vs string builder vs bytes buffer
package main
import (
"bytes"
"strings"
"testing"
)
func BenchmarkStringAppend(b *testing.B) {
for i := 0; i < b.N; i++ {
[alias]
st = status
co = checkout
br = branch
ci = commit -av --no-status -q
unstage = reset HEAD --
last = log -1 HEAD
recent = for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
logd = log --decorate
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
#!/usr/bin/env bash
set -eu
doWork() {
# make modifications here
git br -d $i
}
for i in $(ls); do
@daniellowtw
daniellowtw / time.ahk
Last active August 1, 2020 20:14
Autohotkey RFC3339 datetime with timezone
/*
Usage:
timeStr := Get_now()
MsgBox, %timeStr
*/
Get_now()
{
global
UTCFormatStr := "yyyy-MM-dd'T'HH:mm:ss"
@daniellowtw
daniellowtw / utils.ps1
Created May 15, 2020 07:24
powershell stuff
Get-ChildItem '.*' | foreach {$_.Attributes = $_.Attributes -bor "Hidden"}
# Hide all files and folders that starts with .
# I use this to clean up my home directory.
@daniellowtw
daniellowtw / sshrc
Last active January 17, 2020 17:51
sshrc
#!/usr/bin/env bash
# Source: https://liam.sh/post/importing-bash-functions-over-ssh
sshrc() {
local SSHHOME=${SSHHOME:=~}
if [ ! -f $SSHHOME/.sshrc ]; then
echo "No such file: $SSHHOME/.sshrc"
exit 1
fi
@daniellowtw
daniellowtw / urlencode.sh
Created July 18, 2019 10:16
Encoding url
#Python3
urlencode() {
python -c "import urllib.parse as ul; print(ul.quote_plus('$1'));"
}
#Python2
urlencode() {
python -c "import urllib as ul; print(ul.quote_plus('$1'));"