Skip to content

Instantly share code, notes, and snippets.

View laixintao's full-sized avatar
📟
I live in the terminal.

laixintao

📟
I live in the terminal.
View GitHub Profile
@laixintao
laixintao / decent_request.py
Last active February 20, 2024 12:05
Send HTTP requests using python-requests with timeout, tcp reuse(session) and retry.
from requests.adapters import HTTPAdapter, Retry
from requests import Session
retries = Retry(
total=5, backoff_factor=1, status_forcelist=[502, 503, 504]
)
session = Session() # reuse tcp connection
session.mount("http://", HTTPAdapter(max_retries=retries))
session.mount("https://", HTTPAdapter(max_retries=retries))
@laixintao
laixintao / filemode.py
Last active January 9, 2024 09:50
File mode quiz
# hint: read this link before answering:
# https://stackoverflow.com/questions/1466000/difference-between-modes-a-a-w-w-and-r-in-built-in-open-function
with open("a.txt", "w") as f:
f.write("abcd")
with open("a.txt", "r+") as f:
f.write("x")
x = f.read(1)
print(x)
@laixintao
laixintao / v.xbin.io.bash
Created February 10, 2023 10:15
Run this command to use v.xbin.io
vim -i NONE \
-c 'set nomore' +'redir! > /dev/stdout' \
+'silent! echo "sK7gstart"' \
+'silent! verbose map' \
+'silent! verbose map!' \
+'silent! echo "aYx9end"' \
+'redir END' \
+'qall' | \
curl -X POST --data-binary @- http://127.0.0.1:5005/n
@laixintao
laixintao / eacape_ansi.py
Created January 19, 2023 06:24
remove console code and ansi escape code using Python
def escape_ansi(line):
# 7-bit and 8-bit C1 ANSI sequences
ansi_escape_8bit = re.compile(
rb"""
(?: # either 7-bit C1, two bytes, ESC Fe (omitting CSI)
\x1B
[@-Z\\-_]
| # or a single 8-bit byte Fe (omitting CSI)
[\x80-\x9A\x9C-\x9F]
| # or CSI + control codes
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML5 GetUserMedia Demo</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
</head>
<body>
<input type="button" title="开启摄像头" value="开启摄像头" onclick="getMedia();" /><br />
@laixintao
laixintao / Git常用命令.sh
Last active August 20, 2022 06:52
一些常用的git命令 速查表
------------------------------commit------------------------------
$ git status # 检查文件当前的状态
$ git add [文件名] # 追踪新的文件
$ git diff --cached # 若要看已经暂存起来的文件和上次提交时的快照之间的差异
$ git commit -m "Story 182: Fix benchmark" # 用一行命令提交更新
$ git commit -a -m 'added new benchmarks' # 跳过add命令直接提交
$ git rm --cached log.log # 从git仓库中删除不小心追踪的文件(用于gitignore之前追踪的文件)
$ git mv file_from file_to # 移动文件/重命名文件
------------------------------branch------------------------------
@laixintao
laixintao / in_generator.py
Created April 8, 2022 16:05
You can move put try-catch outside of the generator!
import time
def generate():
try:
for i in range(5):
time.sleep(0.5)
yield i
finally:
print("My jos is done, clock out!")
- #morning-stand-up
- Recap
- Today's plan
- morning announcement:
- yesterday and today's work todos
- {{[[query]]: {and: [[TODO]] {between: [[yesterday]] [[today]]} } }}
aahed
aalii
aapas
aargh
abaca
abaci
aback
abaft
abaka
abamp
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
fmt.Printf("Generated service id: %s\n", CreateServiceID())