This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# Using Flask since Python doesn't have built-in session management | |
from flask import Flask, session, render_template | |
# Our target library | |
import requests | |
import json | |
app = Flask(__name__) | |
# Generate a secret random key for the session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from typing import Dict | |
from dataclasses import ( | |
asdict, dataclass, field, fields, is_dataclass | |
) | |
# 对于一些嵌套的数据类,需要深度遍历 | |
class EnhancedJSONEncoder(json.JSONEncoder): | |
def default(self, o): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 日志打印屏幕或文件 | |
def setup_logger_2(logger_name, level=logging.INFO, handler='all', log_file=''): | |
""" | |
:param logger_name: | |
:param log_file: | |
:param level: | |
:param handler: file or stream or all | |
:return: | |
""" | |
log_setup = logging.getLogger(logger_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
version: 1 | |
disable_existing_loggers: False | |
formatters: | |
simple: | |
format: "%(name)-20s%(levelname)-8s%(message)s" | |
handlers: | |
console: | |
class: logging.StreamHandler | |
level: DEBUG |
NewerOlder