Skip to content

Instantly share code, notes, and snippets.

View wilkice's full-sized avatar
😁
Focusing

darcy wilkice

😁
Focusing
  • Earth
  • 21:09 (UTC +08:00)
View GitHub Profile
@wilkice
wilkice / a.md
Last active January 27, 2022 16:57
常用SQL #sql

show db disk usage

select table_schema, sum((data_length+index_length)/1024/1024) AS "Total size(table+index) Mb", sum(data_length/1024/1024) as "table size", sum(index_length/1024/1024) as "index size" from information_schema.tables group by table_schema;
@wilkice
wilkice / a.md
Created January 19, 2022 10:19
[16 进制转换] #dev

16 进制需要先转为 10 进制的 byte,然后 byte 和 str 相互转换

Python

# ascii str to hex str
"hello".encode().hex()  # '68656c6c6f'

# hex str to ascii
bytes.fromhex("68656c6c6f").decode()  # "hello"
@wilkice
wilkice / main.go
Created December 24, 2021 07:30
[hex, int, string]
package main
import (
"fmt"
"strconv"
"encoding/hex"
)
func main() {
// "A"
@wilkice
wilkice / a.go
Created December 17, 2021 07:46
[go execute command]
package main
import (
"log"
"os/exec"
)
func main() {
cmd := exec.Command("aaa", "-za")
output, err := cmd.CombinedOutput()
@wilkice
wilkice / a.md
Created December 15, 2021 02:45
[nginx load balance by full client ip] #nginx #linux
   upstream apachereadonly  {
     server 10.10.11.10:8011; 
     server 10.10.11.11:8011; 
     server 10.10.11.12:8011; 
	 hash $remote_addr consistent;
   }

Please note the ip_hash of nginx only cares the first thress parts of client ip, so 10.0.0.1/24 all will go to the same backend server.

@wilkice
wilkice / main.py
Created November 12, 2021 09:06
[requsts proxy] use proxy to do requests #py
import requests
import json
url = 'https://httpbin.org/get'
proxies = {
'http': 'http://127.0.0.1:7890',
'https': 'http://127.0.0.1:7890',
}
r = requests.get(url, proxies=proxies)
@wilkice
wilkice / main.go
Created November 12, 2021 09:04
[get outbound ip] #go
import (
"log"
"net"
)
// Get preferred outbound ip of this machine
func GetOutboundIP() net.IP {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
log.Fatal(err)
@wilkice
wilkice / main.go
Created September 13, 2021 08:08
[go decode to nested json] #go
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
@wilkice
wilkice / a.py
Created September 3, 2021 09:55
[pymysql usage] #python
import pymysql
db = pymysql.connect(host="192.168.236.111", user="fakeuser", password="fakepassword",port=xxx, db="xxx")
data = {
"a": 1,
"b": "2,3"
}
table_name="detail"
column_string = ','.join(data.keys())
@wilkice
wilkice / main.go
Last active January 7, 2022 05:22
[go routine pool] #go
// simple go routine pool
package main
import (
"sync"
)
func main() {
var wg sync.WaitGroup