Skip to content

Instantly share code, notes, and snippets.

View zh4n7wm's full-sized avatar
🎯
Focusing

Hydra zh4n7wm

🎯
Focusing
View GitHub Profile
@zh4n7wm
zh4n7wm / chars_number_sorted.py
Last active March 12, 2019 04:57
The number of characters in string
import string
from collections import Counter, defaultdict
limited_chars = string.ascii_letters + string.digits
with open('test_1.txt') as fd:
content = fd.read()
def func_a(s):
@zh4n7wm
zh4n7wm / .ssh_config
Created March 26, 2019 09:02 — forked from andyvanee/.ssh_config
Fix unix_listener too long for Unix domain socket
Host *
ControlPath ~/.ssh/control/%C
ControlMaster auto
@zh4n7wm
zh4n7wm / dumps.py
Last active March 27, 2019 08:38
[python]convert protocol buffer response to json/dict
from google.protobuf.json_format import MessageToDict, MessageToJson
@zh4n7wm
zh4n7wm / decode-double-encoded-data.md
Last active March 27, 2019 11:11
decode double-encoded data

Encoding to Latin 1 lets us interpret characters as bytes to fix the encoding.

Rule of thumb: whenever you have double-encoded data, undo the extra 'layer' of encoding by decoding to Unicode using that codec, then encoding again with Latin-1 to get bytes again.

"»Æ¹ûÊ÷".encode("latin1").decode("gb2312")

from: https://stackoverflow.com/questions/20922024/how-to-convert-encoding-in-python

@zh4n7wm
zh4n7wm / MySQL-to-PostgreSQL.md
Created March 29, 2019 12:34
import MySQL table to PostgreSQL

dump MySQL table

mysql -u root -p <dbname> -e 'select * from <table-name>' > /tmp/<table-name>.csv

format csv file:

TABLE_NAME='<table-name>' python -c "import os, pandas as pd;csv_path='/tmp/{}.csv'.format(os.getenv('TABLE_NAME'));df = pd.read_csv(csv_path, sep='\t');df.to_csv(csv_path, header=True, index=False)"

import to PostgreSQL

@zh4n7wm
zh4n7wm / cyclone.py
Created April 1, 2019 05:25 — forked from makotoworld/cyclone.py
flask deploy tornado
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tornado.wsgi import WSGIContainer
from tornado.ioloop import IOLoop
from tornado.web import FallbackHandler, RequestHandler, Application
from wsgi import app
class MainHandler(RequestHandler):
def get(self):
@zh4n7wm
zh4n7wm / Rearming-images.md
Created April 11, 2019 09:36
Rearming Windows images

Rearming images

For Windows XP, Vista and 7 images you may be able to extend the initial trial usage period once it has expired via the "rearm" process:

  • To rearm a Windows XP image, from the command prompt:

    C:> rundll32.exe syssetup,SetupOobeBnk

  • To rearm Windows Vista and 7 images run the following as an administrator from the command prompt:

@zh4n7wm
zh4n7wm / thunder.md
Created April 15, 2019 08:07
自动重启迅雷

Mac OSX 上的迅雷总是自动退出,下面的小脚本检查到迅雷退出就重新启动它

while true; do sleep 3 && test -z "$(ps aux | grep -w Thunder | grep -vE 'grep|ThunderHelper')" && /Applications/Thunder.app/Contents/MacOS/Thunder ; done

import requests
import sys
import os
import json
MAX_PAGE = 10
if __name__ == "__main__":
'''https://<your_gitlab_site_address>/profile/personal_access_tokens'''
git_urls = []
@zh4n7wm
zh4n7wm / pytest-debug.md
Created April 26, 2019 13:23
pytest can automatically drop into pdb

Lucas Werkmeister

today’s Python discovery: pytest can automatically drop into pdb (python debugger) on assertion failure (pytest --pdb)

@anthonypjshaw

Bonus: use --pdbcls for other debuggers, eg Ipdb is --pdbcls=IPython.terminal.debugger:Pdb