Skip to content

Instantly share code, notes, and snippets.

View hzhu212's full-sized avatar

Henry Zhu hzhu212

  • Beijing, China
View GitHub Profile
@hzhu212
hzhu212 / coderun.json
Last active April 22, 2024 06:51
coderun-echarts
{"config":{"codeTheme":"OneDarkPro","pageThemeSyncCodeTheme":true,"openAlmightyConsole":true,"autoRun":true,"layout":"edit","keepPreviousLogs":true,"codeFontSize":14},"title":"coderun-echarts","code":{"HTML":{"language":"html","content":"<!-- 为ECharts准备一个具备大小(宽高)的Dom -->\n<div id=\"main\" style=\"width: 800px; height:600px;\"></div>","resources":[]},"CSS":{"language":"css","content":"","resources":[]},"JS":{"language":"javascript","content":"// 基于准备好的dom,初始化echarts实例\nvar myChart = echarts.init(document.getElementById(\"main\"));\n\n// 指定图表的配置项和数据\n// prettier-ignore\nconst hours = [\n '0','1星','2星','3星','4星','5星','6'\n];\n\n// prettier-ignore\nconst days = [\n '智驾车型覆盖度',\t'自动泊车',\t'记忆泊车',\t'高速LCC',\t'城区LCC',\t'高速领航辅助驾驶',\t'城区领航辅助驾驶'\n];\n\n// prettier-ignore\nconst data = [[0, 3, 1], [0, 4, 4], [0, 5, 1], [1, 4, 6], [2, 3, 1], [2, 5, 3], [3, 5, 6], [4, 4, 3], [4, 5, 3], [5, 3, 1], [5, 4, 2], [5, 5, 3], [6, 3, 1], [6, 4, 2], [6, 5, 2]];\nconst title = [];\nconst singleAxis = [];\nconst series = [];\ncon
@hzhu212
hzhu212 / competitive_parallel.py
Last active April 23, 2024 03:54
Python competitive parallel / race concurrent / ThreadPool / ProcessPool
from concurrent.futures import as_completed
from concurrent.futures.process import ProcessPoolExecutor
import os
import psutil
import time
def kill_child_processes(parent_pid):
try:
parent = psutil.Process(parent_pid)
package com.example.udf;
import com.google.common.base.Throwables;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
@hzhu212
hzhu212 / python_shell.md
Created May 12, 2021 12:50
Wrap shell command with subprocess

Wrap shell command with subprocess

create a simple HDFS client for example:

import logging
import subprocess
from typing import List, Tuple, Union, TextIO, BinaryIO
@hzhu212
hzhu212 / python_retry.md
Last active May 12, 2021 12:23
A simple Python retrying decorator

A simple Python retrying decorator

Define:

import functools
import logging

logger = logging.getLogger(__name__)
@hzhu212
hzhu212 / jupyter.md
Last active December 7, 2023 01:59
一些 Jupyter 技巧

任意一个 cell 出现异常执行 callback

# this function will be called on exceptions in any cell
def when_exception(shell, etype, evalue, tb, tb_offset=None):
    # still show the error within the notebook, don't just swallow it
    shell.showtraceback((etype, evalue, tb), tb_offset=tb_offset)

    err_msg = f'Unexpected exception occured: {repr(evalue)}'
 logger.error(err_msg)
@hzhu212
hzhu212 / python_protobuf.md
Last active December 11, 2020 08:21
python protobuf wrapper

A wrapper for Python protobuf object:

class PbMessage(object):
    """protobuf 消息的包装类,封装一些通用方法"""

    def __init__(self, pb_class):
        self._pb_class = pb_class
        self._pb_obj = None
        self._raw_msg = None
@hzhu212
hzhu212 / python_stream.md
Last active August 25, 2023 09:22
Python iterator with chain-call like Java stream

Python Stream object act like Java Stream, features include lazy calculating, slicing, chain-call etc.

stream.py:

import functools
import itertools


class Stream(object):
@hzhu212
hzhu212 / python_cache.md
Last active May 12, 2021 12:24
something about cache

a threading-safe cache decorator, cache result of function returns

from functools import wraps
import threading


class CallCache(object):
    def __init__(self):
 self.lock = threading.RLock()
@hzhu212
hzhu212 / cmd_bat.md
Last active July 7, 2024 19:24
Windows cmd/bat 相关

Windows cmd/bat 相关

后台执行命令

cmd 中后台执行命令,相当于 bash 中的&

start /b <your_command>