Skip to content

Instantly share code, notes, and snippets.

View justdoit0823's full-sized avatar

余森彬 justdoit0823

View GitHub Profile
@justdoit0823
justdoit0823 / kafka_consumer_group_rebalance.md
Created March 22, 2019 07:28
Kafka consumer group rebalance process.

Kafka commands

  • list consumer group members
kafka-consumer-groups --describe  --bootstrap-server localhost:9092 --group g1 --members
@justdoit0823
justdoit0823 / guava_loading_cache._refresh_process.md
Last active February 16, 2019 09:48
Guava LocalLoadingCache refresh process.

LocalLoadingCache.get

  • living value exists

When it's time to refresh, competing for the asynchronous loading with the specified loader. If the loading thread is immediately done, returning the new value. Otherwise returning the current living value. Finally, the cache will be updated with the loading value.

@justdoit0823
justdoit0823 / str_and_format_string_in_python37.md
Created December 28, 2018 12:09
Compare `str` function and format string in Python 3.7
  • Benchmark result
root@localhost:~# python3.7 -m timeit -s 'x = 6' 'f"{x}"'
5000000 loops, best of 5: 79 nsec per loop
root@localhost:~# python3.7 -m timeit -s 'x = 6' 'str(x)'
1000000 loops, best of 5: 214 nsec per loop
@justdoit0823
justdoit0823 / hadoop_utils.py
Last active December 30, 2018 01:43
Hadoop utilities with python.
# 汇总hdfs web上文件大小
def hdfs_file_size(path):
s_data = open(path).read()
data = s_data.split('\n')
s_size = tuple(r.split('\t')[3].split(' ')[0] for r in data if r)
return sum(map(float, s_size))
# 打开yarn任务页面
def open_yarn_application_page(app_name):
import requests
@justdoit0823
justdoit0823 / mysql_auto_increment.sql
Last active October 27, 2018 07:25
mysql auto increment.
drop table if exists s_test_mysql_auto_increment;
create table s_test_mysql_auto_increment(id int primary key auto_increment, value int);
insert into s_test_mysql_auto_increment(value) values (10000);
SELECT `AUTO_INCREMENT`
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 's_test_mysql_auto_increment';
insert into s_test_mysql_auto_increment(value) values (10001);
SELECT `AUTO_INCREMENT`
@justdoit0823
justdoit0823 / redis_data_type.md
Last active October 27, 2018 06:42
Redis internal data type analysis.

Internal basic type

  • hashtable
typedef struct dict {
    dictType *type;
    void *privdata;
@justdoit0823
justdoit0823 / ipython_autoreload.md
Created October 8, 2018 08:26
iPython enable autoreload configuration.
  • create ipython profile
ipython profile create default
  • edit profile
@justdoit0823
justdoit0823 / rm_path_prefix_in_nginx.conf
Created July 14, 2018 07:17
remove path prefix in nginx
# Use rewrite directive
location ^~ /apps/ {
rewrite ^/apps/(.*) /$1 break;
proxy_pass http://127.0.0.1:3000$uri$is_args$args;
}
# Use location path match
location ^~ /apps/ {
proxy_pass http://127.0.0.1:3000/;
function show_haproxy_socket_info(){
ret=$(ss -tnlp|grep haproxy)
echo $ret
pstr=$(echo $ret | awk -F'\t' '{split($NF, a, ","); split(a[2], b, "="); split(a[3], c, "="); split(c[2], d, ")"); print b[2], d[1]}')
IFS=' '
read -r -a array <<< "$pstr"
pid="${array[0]}"
@justdoit0823
justdoit0823 / cpython_generator_versus_greenlet.md
Created May 14, 2018 09:11
CPython generator versus greenlet.

Generator

  • shared frame object

  • multiple executions of the frame

greenlet