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 / files.txt
Created July 21, 2021 03:22
files in gavinmroy/alpine-redis 5.0.9-0 d6617494cb6d 8 months ago 6.96MB docker image.
.
├── bin
│   ├── arch -> /bin/busybox
│   ├── ash -> /bin/busybox
│   ├── base64 -> /bin/busybox
│   ├── bbconfig -> /bin/busybox
│   ├── busybox
│   ├── cat -> /bin/busybox
│   ├── chgrp -> /bin/busybox
│   ├── chmod -> /bin/busybox
number1| x| name
4x| 3| Hi
2| 1|808890312093
5|Hi| Bye
@laixintao
laixintao / with_lock.py
Last active May 20, 2021 05:56
list.append is an atomic action, so no lock needed when multiple threads append on same list.
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)}")
def foo(num):
print("foo run")
return num ** 20
def bar(x):
if 0:
print(x)
import ctypes
def deref(addr, typ):
return ctypes.cast(addr, ctypes.POINTER(typ))
deref(id(3), ctypes.c_int)[6] = 2
#!/usr/bin/env python
import sys
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.contrib.regular_languages.compiler import compile
from prompt_toolkit.lexers import Lexer, PygmentsLexer, SimpleLexer
from prompt_toolkit.contrib.regular_languages.completion import GrammarCompleter
from prompt_toolkit.contrib.regular_languages.lexer import GrammarLexer
animal_completer = WordCompleter(
" ## Ussage
" install vim-plug( https://github.com/junegunn/vim-plug )
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" Run: PlugInstall
" General settings --------------------{{{
set encoding=utf-8
let mapleader=','
syntax enable
import os
parent_pid = os.getpid()
print("parent pid: ", parent_pid)
forked_pid = os.fork()
print("forked_pid: ", forked_pid)
parent_pid = os.getpid()
print("my pid: ", parent_pid)
# -*- coding: utf-8 -*-
import os
import sys
from prompt_toolkit import prompt
pid = os.getpid()
print("old: ", pid)
forked_pid = os.fork()
print("forked pid: ", forked_pid)
class Foo:
foo = "hello"
def print(self):
print(self.foo)
class Bar:
foo = "world"