This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"go/build" | |
"go/types" | |
"os" | |
"golang.org/x/tools/go/loader" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/signal" | |
"syscall" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Snippet #2 | |
f = open(FILENAME, 'rb') | |
data = bytearray(f.read()) | |
data[0] = 97 # OK! | |
# Snippet #3 | |
f = open(FILENAME, 'rb') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |