Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I wrote like 10 lines of code a week then I sleep.

laixintao

💭
I wrote like 10 lines of code a week then I sleep.
View GitHub Profile
@laixintao
laixintao / in_generator.py
Created Apr 8, 2022
You can move put try-catch outside of the generator!
View in_generator.py
import time
def generate():
try:
for i in range(5):
time.sleep(0.5)
yield i
finally:
print("My jos is done, clock out!")
View my-daily-template.txt
- #morning-stand-up
- Recap
- Today's plan
- morning announcement:
- yesterday and today's work todos
- {{[[query]]: {and: [[TODO]] {between: [[yesterday]] [[today]]} } }}
View uniq-wordle.txt
aahed
aalii
aapas
aargh
abaca
abaci
aback
abaft
abaka
abamp
View uniq.go
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
fmt.Printf("Generated service id: %s\n", CreateServiceID())
View asy.py
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)
View hide-bilibili-popup.js
// ==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==
@laixintao
laixintao / files.txt
Created Jul 21, 2021
files in gavinmroy/alpine-redis 5.0.9-0 d6617494cb6d 8 months ago 6.96MB docker image.
View files.txt
.
├── bin
│   ├── arch -> /bin/busybox
│   ├── ash -> /bin/busybox
│   ├── base64 -> /bin/busybox
│   ├── bbconfig -> /bin/busybox
│   ├── busybox
│   ├── cat -> /bin/busybox
│   ├── chgrp -> /bin/busybox
│   ├── chmod -> /bin/busybox
View output
number1| x| name
4x| 3| Hi
2| 1|808890312093
5|Hi| Bye
@laixintao
laixintao / with_lock.py
Last active May 20, 2021
list.append is an atomic action, so no lock needed when multiple threads append on same list.
View with_lock.py
urls_to_download = ['baidu.com', 'taobao.com', 'zhihu.com', 'douban.com']
done_count = 0
done_count_lock = Lock()
def download(url):
requests.get(url)
with done_count_lock:
done_count += 1
print(f"currnet process: {done_count} / {len(urls_to_download)}")
View a.py
def foo(num):
print("foo run")
return num ** 20
def bar(x):
if 0:
print(x)