Skip to content

Instantly share code, notes, and snippets.


LI Zhennan nanmu42

View GitHub Profile
View file_extension_to_MIME.json
nanmu42 / GetMyIP.go
Created June 6, 2018 10:22
Get My IP - Golang
View GetMyIP.go
package main
import (
func main() {
nanmu42 / airdroper.sol
Created August 2, 2018 04:36
Airdropper for any ERC20 contract
View airdroper.sol
pragma solidity ^0.4.24;
interface Token {
function transfer(address _to, uint256 _value) external returns (bool);
contract onlyOwner {
address public owner;
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
nanmu42 /
Last active April 5, 2022 22:51
Update tmux to latest version
#!/usr/bin/env bash
set -e
# dependecies
apt update
apt install -y git automake build-essential pkg-config libevent-dev libncurses5-dev byacc
# where our temp file locates
rm -rf /tmp/tmux
nanmu42 / random_string.js
Created March 7, 2019 07:52
Javascript Ramdom String With Specific Length
View random_string.js
// change 10 to the length desired
nanmu42 / randomstring.go
Created March 7, 2019 10:25
Superfast Golang Random String
View randomstring.go
// credits:
import (
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const (
letterIdxBits = 6 // 6 bits to represent a letter index
nanmu42 / pkcs7padding.go
Last active December 20, 2022 03:01
Golang PKCS7 Padding/Unpadding
View pkcs7padding.go
// pkcs7strip remove pkcs7 padding
func pkcs7strip(data []byte, blockSize int) ([]byte, error) {
length := len(data)
if length == 0 {
return nil, errors.New("pkcs7: Data is empty")
if length%blockSize != 0 {
return nil, errors.New("pkcs7: Data is not block-aligned")
padLen := int(data[length-1])
nanmu42 / Dockerfile
Last active January 29, 2021 05:52
Minimal-sized Golang Docker Image
View Dockerfile
FROM golang:1-alpine as golang
RUN apk --no-cache add git zip tzdata ca-certificates
# avoid go path, use go mod
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-s -w -extldflags "-static"" ./cmd/appnamehere
WORKDIR /usr/share/zoneinfo
# -0 means no compression. Needed because go's
# tz loader doesn't handle compressed data.
RUN zip -r -0 / .
nanmu42 / Dockerfile
Last active May 15, 2019 08:01
Docker loves Vue.js
View Dockerfile
FROM node:10.15 as builder
WORKDIR /project
COPY . .
RUN npm i && npm run lint && npm run build && rm -f dist/**/*.map
FROM nginx:stable
# COPY copies folder content, not folder itself
COPY --from=builder /project/dist /var/www
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
nanmu42 /
Last active May 16, 2019 05:00
ffmpeg compressing video for web browser
#!/usr/bin/env bash
# preset veryslow: more time for more compressing rate
# -movflags +faststart optimizes for web browser so video can be played sooner.
# crf: small = better quality + bigger size; sane option between 17–28
ffmpeg -i "$SRC" -vcodec libx264 -crf "$CRF" -movflags +faststart -preset veryslow -profile:v high -level 4.1 web_libx264_crf_${CRF}_faststart_veryslow.mp4