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
View reload.py
# -*- 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)
View unbound.py
class Foo:
foo = "hello"
def print(self):
print(self.foo)
class Bar:
foo = "world"
View try.py
# -*- coding: utf-8 -*-
from ratelimit import limits, sleep_and_retry
from time import time
count = 0
@sleep_and_retry
@limits(calls=3, period=5)
def call_api():
View subprocess_with_open_not_working.py
from subprocess import run
# not working, Bad file descriptor
run(
"head /dev/random -c 100",
stdout=open("/tmp/head.out", "wb", 0).fileno(),
shell=True,
)
View 6.48. Libelf from Elfutils-0.177
PASS: run-backtrace-fp-core-x86_64.sh
PASS: run-backtrace-fp-core-aarch64.sh
PASS: run-backtrace-fp-core-ppc64le.sh
PASS: run-backtrace-core-x32.sh
PASS: run-backtrace-core-i386.sh
PASS: run-backtrace-fp-core-i386.sh
PASS: run-backtrace-core-ppc.sh
PASS: run-backtrace-core-s390x.sh
PASS: run-backtrace-core-s390.sh
PASS: run-backtrace-core-aarch64.sh
View antd-bug.js
import React, { Component } from '@alipay/bigfish/react'
import { Flex, Card, WingBlank, WhiteSpace } from 'antd-mobile'
export default class ExampleCard extends Component {
render() {
return (
<WingBlank size="lg">
<WhiteSpace size="lg" />
<Card>
<Card.Header
View redis_re.py
# -*- coding: utf-8 -*-
import re
re.compile(r'^(?:(?:\s){0,}(?P<n0>(?:CLUSTER(?:\s){1,}ADDSLOTS|CLUSTER(?:\s){1,}DELSLOTS|cluster(?:\s){1,}addslots|cluster(?:\s){1,}delslots))(?:\s){1,}(?P<n1>(?:\d){1,}(?:(?:\s){1,}(?:\d){1,}){0,})(?:\s){0,}|(?:\s){0,}(?P<n2>(?:CLUSTER(?:\s){1,}COUNT-FAILURE-REPORTS|CLUSTER(?:\s){1,}FORGET|CLUSTER(?:\s){1,}REPLICAS|CLUSTER(?:\s){1,}REPLICATE|CLUSTER(?:\s){1,}SLAVES|cluster(?:\s){1,}count-failure-reports|cluster(?:\s){1,}forget|cluster(?:\s){1,}replicas|cluster(?:\s){1,}replicate|cluster(?:\s){1,}slaves))(?:\s){1,}(?P<n3>(?:\d){1,})(?:\s){0,}|(?:\s){0,}(?P<n4>(?:CLUSTER(?:\s){1,}COUNTKEYSINSLOT|cluster(?:\s){1,}countkeysinslot))(?:\s){1,}(?P<n5>(?:\d){1,})(?:\s){0,}|(?:\s){0,}(?P<n6>(?:CLUSTER(?:\s){1,}FAILOVER|cluster(?:\s){1,}failover))(?:\s){1,}(?P<n7>(?:FORCE|TAKEOVER|force|takeover))(?:\s){0,}|(?:\s){0,}(?P<n8>(?:CLUSTER(?:\s){1,}RESET|cluster(?:\s){1,}reset))(?:\s){1,}(?P<n9>(?:HARD|SOFT|hard|soft))(?:\s){0,}|(?:\s){0,}(?P<n10>(?:CLUSTER(?:\s){1,}GETKEYSINSLOT|cluster
@laixintao
laixintao / t.sh
Created Sep 16, 2019
Difference between $* and $@
View t.sh
echo "\$* in quotes..."
for v in "$*"
do
echo $v
done
echo "\$@ in quotes..."
for v in "$@"
do
echo $v
View in-place-convert-encoding.sh
for file in $(fd -x file | rg "UTF-8" | cut -f1 -d":")
do
echo "convert ${file}..."
iconv -f utf8 -t gbk "$file" > "$file.new" &&
mv -f "$file.new" "$file"
done
View show_db_size.sql
SELECT table_schema "DB Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;