Skip to content

Instantly share code, notes, and snippets.

@xtao
xtao / decode_email.py
Created February 24, 2024 17:44 — forked from sdkn104/decode_email.py
Python script to decode email
import imaplib, email, email.parser, email.policy
import html2text
import pprint, sys
#
# Utilities for Debug
#
pp = pprint.PrettyPrinter(indent=4, width=80)
def myprint(str):
@xtao
xtao / chatglm-openai-api.ipynb
Created April 21, 2023 01:35 — forked from ninehills/chatglm-openai-api.ipynb
chatglm-openai-api.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xtao
xtao / nginx.conf
Created March 17, 2019 07:37 — forked from fotock/nginx.conf
Nginx SSL 安全配置最佳实践.
# 生成 dhparam.pem 文件, 在命令行执行任一方法:
# 方法1: 很慢
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
# 方法2: 较快
# 与方法1无明显区别. 2048位也足够用, 4096更强
openssl dhparam -dsaparam -out /etc/nginx/ssl/dhparam.pem 4096
# http://code.activestate.com/recipes/474088-tail-call-optimization-decorator/
#!/usr/bin/env python2.4
# This program shows off a python decorator(
# which implements tail call optimization. It
# does this by throwing an exception if it is
# it's own grandparent, and catching such
# exceptions to recall the stack.
import sys
@xtao
xtao / Install NVIDIA Driver and CUDA.md
Created January 27, 2018 07:15 — forked from wangruohui/Install NVIDIA Driver and CUDA.md
Install NVIDIA Driver and CUDA on Ubuntu / CentOS / Fedora Linux OS
## Internal
- SSH
- Python
- YAML
## Concepts
- Inventory
- Playbooks
- Roles
- Tasks/Handlers/Vars
# author: jiangchengyao@gmail.com
[mysql]
prompt = [\\u@\\h][\\d]>\\_
[mysqld]
# basic settings #
user = mysql
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
autocommit = 1
@xtao
xtao / sqlite2mysql.perl
Created September 13, 2016 04:13
sqlite2mysql.perl
#! /usr/bin/perl
while ($line = <>){
if (($line !~ /BEGIN TRANSACTION/) && ($line !~ /COMMIT/) && ($line !~ /sqlite_sequence/) && ($line !~ /CREATE UNIQUE INDEX/)){
if ($line =~ /CREATE TABLE \"([a-z_]*)\"(.*)/){
$name = $1;
$sub = $2;
$sub =~ s/\"//g;
$line = "DROP TABLE IF EXISTS $name;\nCREATE TABLE IF NOT EXISTS $name$sub\n";
@xtao
xtao / distribution.py
Created June 4, 2016 05:39 — forked from tarekziade/distribution.py
Consistent Distribution of users across servers
""" Consistent load-balancing.
We have a few servers and we want a load-balancer to
distribute incoming requests across them in a deterministic
and consistent way - without keeping any counter to make the
decision.
Removing a backend server should not impact users on other
servers.
@xtao
xtao / sse.py
Created May 29, 2016 11:25
Python SSE Client
import urllib
response = urllib.urlopen('http://192.168.77.21:9001/v2/coreinfowatcher?watch=1&heartbeat=1')
for line in response:
print line