Skip to content

Instantly share code, notes, and snippets.

View rebornwwp's full-sized avatar
😕
Working from home

u rebornwwp

😕
Working from home
View GitHub Profile
@rebornwwp
rebornwwp / ssadump.go
Created December 23, 2021 09:31 — forked from ksurent/ssadump.go
Print Go's SSA form, much like ssadump but with concrete types
package main
import (
"flag"
"fmt"
"go/build"
"go/types"
"os"
"golang.org/x/tools/go/loader"
@rebornwwp
rebornwwp / shell
Last active January 10, 2021 19:01
go_coverage_for_function
cover () {
local t=$(mktemp -t cover)
go test $COVERFLAGS -coverprofile=$t $@ \
&& go tool cover -func=$t \
&& unlink $t
}
cover-web() {
t=$(tempfile)
go test $COVERFLAGS -coverprofile=$t $@ && go tool cover -html=$t && unlink $t
@rebornwwp
rebornwwp / Makefile
Created October 19, 2020 12:17 — forked from kwilczynski/Makefile
Makefile for my Go projects (an example).
SHELL := /bin/bash
REV := $(shell git rev-parse HEAD)
CHANGES := $(shell test -n "$$(git status --porcelain)" && echo '+CHANGES' || true)
TARGET := packer-provisioner-itamae-local
VERSION := $(shell cat VERSION)
OS := darwin freebsd linux openbsd
ARCH := 386 amd64
@rebornwwp
rebornwwp / signal.go
Created October 17, 2020 12:11 — forked from reiki4040/signal.go
signal handling example for golang
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
@rebornwwp
rebornwwp / Makefile
Created September 26, 2020 10:26 — forked from rlespinasse/Makefile
guard-makefile
task-who-need-specific-envvar: guard-SPECIFIC_ENVVAR
@echo ${SPECIFIC_ENVVAR}
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
# $ make task-who-need-specific-envvar
@rebornwwp
rebornwwp / Makefile
Created July 13, 2020 18:20 — forked from sighingnow/Makefile
Detect operating system in Makefile.
# Detect operating system in Makefile.
# Author: He Tao
# Date: 2015-05-30
OSFLAG :=
ifeq ($(OS),Windows_NT)
OSFLAG += -D WIN32
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
OSFLAG += -D AMD64
endif
@rebornwwp
rebornwwp / Makefile
Created March 5, 2020 14:14
Makefile help target example
# Makefile with help target. from https://blog.thapaliya.com/posts/well-documented-makefiles/
.DEFAULT_GOAL:=help
SHELL:=/bin/bash
##@ Dependencies
.PHONY: deps
deps: ## Check dependencies
$(info Checking and getting dependencies)
@rebornwwp
rebornwwp / txt
Created July 9, 2019 16:35
docker工程实践
FROM debian
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
openjdk-8-jdk
# 删除不需要的apt包
&& rm -rf /var/lib/apt/lists/*
# 如果数据能编译成一个可执行文件,尽量能够精确复制。
COPY /target/a.jar /app
@rebornwwp
rebornwwp / buffer.py
Created March 9, 2019 08:20
Less copies in Python with the buffer protocol and memoryviews
# Snippet #2
f = open(FILENAME, 'rb')
data = bytearray(f.read())
data[0] = 97 # OK!
# Snippet #3
f = open(FILENAME, 'rb')
@rebornwwp
rebornwwp / prime_factors_haskell
Last active July 23, 2018 15:28
将一个数分解成多个素数的乘积
factors' :: Integral t => t -> [t]
factors' n
| n < 0 = factors' (-n)
| n > 0 = if 1 == n
then []
else let fac = mfac n 2 in fac : factors' (n `div` fac)
where mfac m x
| rem m x == 0 = x
| x * x > m = m
| otherwise = mfac m (if odd x then x + 2 else x + 1)