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
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"
# -*- 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():
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,
)
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
# -*- 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 September 16, 2019 11:34
Difference between $* and $@
echo "\$* in quotes..."
for v in "$*"
do
echo $v
done
echo "\$@ in quotes..."
for v in "$@"
do
echo $v
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
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;