Skip to content

Instantly share code, notes, and snippets.

View whiler's full-sized avatar
🇨🇳

whiler whiler

🇨🇳
View GitHub Profile
@whiler
whiler / validator.go
Created March 4, 2024 00:45
golang validator simple usage
import "github.com/go-playground/validator/v10"
type Base struct {
Name string `yaml:"name" validate:"required"`
}
type Ext struct {
ID int `yaml:"id" validate:"gte=1,lt=10"`
}
@whiler
whiler / 91-use-proxy
Created December 25, 2023 04:25
apt uses socks5 proxy (/etc/apt/apt.conf.d/91-use-proxy)
Acquire::http::proxy "socks5h://127.0.0.1:1080";
Acquire::https::proxy "socks5h://127.0.0.1:1080";
@whiler
whiler / gen-cert.sh
Created May 26, 2023 11:07
一行命令生成自签名的 ECC TLS 证书
#!/bin/bash
openssl req \
-new \
-newkey ec \
-pkeyopt ec_paramgen_curve:secp384r1 \
-sha256 \
-days 92 \
-nodes \
-x509 \
@whiler
whiler / svg2png.go
Created May 17, 2023 13:19
使用 golang 将 SVG 图像转换成 PNG 图像
package main
import (
"bytes"
"image"
"image/png"
"io"
"github.com/srwiley/oksvg"
"github.com/srwiley/rasterx"
@whiler
whiler / pi.go
Last active February 18, 2023 01:11 — forked from taiypeo/pi.go
Concurrent π calculation with Golang!
package main
import (
"fmt"
"math"
"runtime"
"time"
)
// Using the Bailey–Borwein–Plouffe formula
@whiler
whiler / mvfunc.sh
Created November 29, 2021 12:21
rename bash shell function
mvfunc() {
local original="$(declare -f $1)"
local newname="$2${original#$1}"
eval "${newname}"
}
@whiler
whiler / create-a-workable-IPv6-network-for-ocserv-clients.md
Created June 6, 2021 05:40
create a workable IPv6 network for ocserv clients

create a workable IPv6 network for ocserv clients

  1. enable NDP proxy at ocserv server host: sysctl -w net.ipv6.conf.all.proxy_ndp=1 .

  2. assign a sub network of ocserv server host IPv6 network for clients, for example:

    if the IPv6 address of ocserv server host inteface eth0 is 2608:8207:7888:a450::1/64, then add the fellowing lines into ocserv.conf:

    ipv6-network = 2608:8207:7888:a450:cafe::/80
    
@whiler
whiler / extfile
Created April 25, 2021 16:23
generate the self-signed Certificate Authority and one certificate for localhost
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth,clientAuth
subjectAltName = @altnames
[altnames]
DNS.1 = localhost
DNS.2 = 127.0.0.1
DNS.3 = ::1
@whiler
whiler / adblock2domains.py
Created December 4, 2020 20:59
get domains from adblock rules in Python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import ipaddress
import re
HEAD = re.compile('^(\|\|?)?(https?://)?')
TAIL = re.compile('(/.*$)|(%2f.*$)|(%2F.*$)')
@whiler
whiler / httpc.go
Last active November 17, 2020 08:57
default http client in golang
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 5 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
TLSHandshakeTimeout: 5 * time.Second,
ExpectContinueTimeout: 5 * time.Second,
ResponseHeaderTimeout: 7 * time.Second,
IdleConnTimeout: 5 * time.Second,