Skip to content

Instantly share code, notes, and snippets.

View changkun's full-sized avatar
🏠
https://changkun.de

Changkun Ou changkun

🏠
https://changkun.de
View GitHub Profile
@changkun
changkun / monitor.go
Created August 7, 2018 08:27
go monitor
package main
import (
"encoding/json"
"fmt"
"runtime"
"time"
)
type Monitor struct {
@changkun
changkun / sockpair2conn.go
Created September 16, 2018 18:39
Golang syscall.Socketpair to net.Conn
func Socketpair() (net.Conn, net.Conn, error) {
fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0)
if err != nil {
return nil, nil, err
}
c1, err := fdToFileConn(fds[0])
if err != nil {
return nil, nil, err
}
@changkun
changkun / matmul.go
Created September 16, 2018 22:25
block/tiling matmul
package main
import (
"log"
"math/rand"
"time"
)
const (
size = 1000
@changkun
changkun / main.go
Last active September 25, 2018 18:51
Test pango
package main
/*
#cgo CFLAGS: -I/usr/local/include/pango-1.0
#cgo CFLAGS: -I/usr/local/include/glib-2.0
#cgo CFLAGS: -I/usr/local/include/cairo
#cgo LDFLAGS: -L/usr/local/lib -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0
#include <pango/pangocairo.h>
#include <stdio.h>
#include <pthread.h>
@changkun
changkun / stacklog2.go
Created September 28, 2018 07:31
log2 for int
// stacklog2 returns ⌊log_2(n)⌋.
func stacklog2(n uintptr) int {
log2 := 0
for n > 1 {
n >>= 1
log2++
}
return log2
}
@changkun
changkun / go-os-arch.md
Created September 30, 2018 09:42 — forked from asukakenji/0-go-os-arch.md
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.8.3 darwin/amd64.

A list of valid GOOS values

(Bold = supported by go out of the box, ie. without the help of a C compiler, etc.)

  • android
  • darwin
@changkun
changkun / go_cpu_memory_profiling_benchmarks.sh
Created October 9, 2018 15:12 — forked from arsham/go_cpu_memory_profiling_benchmarks.sh
Go cpu and memory profiling benchmarks. #golang #benchmark
FILENAME=$(basename $(pwd))
go test -run=. -bench=. -cpuprofile=cpu.out -benchmem -memprofile=mem.out -trace trace.out
go tool pprof -pdf $FILENAME.test cpu.out > cpu.pdf && open cpu.pdf
go tool pprof -pdf --alloc_space $FILENAME.test mem.out > alloc_space.pdf && open alloc_space.pdf
go tool pprof -pdf --alloc_objects $FILENAME.test mem.out > alloc_objects.pdf && open alloc_objects.pdf
go tool pprof -pdf --inuse_space $FILENAME.test mem.out > inuse_space.pdf && open inuse_space.pdf
go tool pprof -pdf --inuse_objects $FILENAME.test mem.out > inuse_objects.pdf && open inuse_objects.pdf
go tool trace trace.out
go-torch $FILENAME.test cpu.out -f ${FILENAME}_cpu.svg && open ${FILENAME}_cpu.svg
@changkun
changkun / helloworld.pl
Created April 10, 2019 06:49
perl in an hour
#!/usr/bin/perl -w
use strict;
use warnings;
# 单行注释
print('Hello,
$world!\n');
my $world = "world";
print "Hello,
@changkun
changkun / main.txt
Created April 28, 2019 08:20
cgo problem
https://github.com/golang/go/issues/7560
https://github.com/golang/go/commit/2d1a9510edc59cad463029fdc8ac93e62247baad
https://dave.cheney.net/2015/10/09/padding-is-hard
@changkun
changkun / gist:2a77a60c046dbdd4601c71dc0d9236fc
Created April 29, 2019 11:43
docker remove all containers
docker rm $(docker ps -a -q)