Skip to content

Instantly share code, notes, and snippets.

@hxer
hxer / dict_dataclass.py
Last active November 1, 2022 08:02
复杂dict对象转换dataclass对象
import json
from typing import Dict
from dataclasses import (
asdict, dataclass, field, fields, is_dataclass
)
# 对于一些嵌套的数据类,需要深度遍历
class EnhancedJSONEncoder(json.JSONEncoder):
def default(self, o):
@hxer
hxer / local-debug-cluster.sh
Last active September 24, 2019 03:06
单机集群启动脚本可调试
#!/bin/bash
# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@hxer
hxer / batch.py
Created June 12, 2019 09:41
可迭代对象按固定大小chunk分割,不补齐
from itertools import islice, chain
#!/usr/bin/python3
def batch(iterable, size):
source_iter = iter(iterable)
while True:
batch_iter = islice(source_iter, size)
try:
first_element = next(batch_iter)
except StopIteration:
@hxer
hxer / nginx.conf
Last active May 13, 2019 03:48
nginx反向代理
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.domain.com;
location / {
proxy_pass http://www.example.com;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@hxer
hxer / mail_template.py
Created May 5, 2019 04:27
jinja2渲染HTML邮件
# -*- coding:utf-8 -*-
from jinja2 import Environment
from jinja2 import FileSystemLoader
if __name__ == "__main__"
data = {}
env = Environment(loader=FileSystemLoader('{0}/templates/'.format(os.path.dirname(__file__))))
template = env.get_template('risk_rule_daily.html')
html = template.render(**data)
@hxer
hxer / pom.xml
Created January 13, 2019 02:15
pom.xml in flink scala demo
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.eflink</groupId>
<artifactId>word-count</artifactId>
<version>1.0</version>
@hxer
hxer / logging.yaml
Last active July 26, 2018 06:09 — forked from JesseBuesking/logging.yaml
python2 MultiProcess Log
---
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(name)-20s%(levelname)-8s%(message)s"
handlers:
console:
class: logging.StreamHandler
level: DEBUG
#!/bin/sh
#
# Script to start CPU limit daemon
#
set -e
case "$1" in
start)
if [ $(ps -eo pid,args | gawk '$3=="/usr/bin/cpulimit_daemon.sh" {print $1}' | wc -l) -eq 0 ]; then
nohup /usr/bin/cpulimit_daemon.sh >/dev/null 2>&1 &
# T-POT 针对中国区替换国内加速镜像 ubuntu 16.04
# https://github.com/n3uz/t-pot-autoinstall
#!/bin/bash
#####################################################################
# 仅限中国网使用,加速都是针对中国的,国外会减速
# This script is used for ubuntu16.04 in China!!!!!!
# If you are out of the GFW,It's sloooooooooooooooooooooooooooooow
# 1、修改Ubuntu源为中国镜像
@hxer
hxer / unlink.py
Created December 2, 2017 13:17
pwnable.kr unlink, gcc -m32 unlink.c -o unlink, ref: https://medium.com/@c0ngwang/pwnable-kr-writeup-unlink-6d2023c2fa13