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 / 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 / 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 / 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
@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())
import asyncio
async def subshell():
print("start sleep...")
process = await asyncio.create_subprocess_shell(
"sleep 23",
)
print("sub process create, my id {}".format(process, process.pid))
await asyncio.sleep(23)
// ==UserScript==
// @name Hide bilibili video popup
// @namespace http://tampermonkey.net/
// @version 0.1
// @description hide annoying pop up choices.
// @author laixintao
// @match https://www.bilibili.com/*
// @icon https://www.google.com/s2/favicons?domain=bilibili.com
// @grant GM_addStyle
// ==/UserScript==