Skip to content

Instantly share code, notes, and snippets.

@tanbro
tanbro / printver.py
Created January 15, 2015 03:19
printver -- print version and date of python modules
#!/usr/bin/env python
# encoding: utf-8
'''
printver -- print version and date of python modules
print module's __version__, __date__ and __updated__ variable
:author: Liu Xue Yan
:mail: tanbro@163.com
'''
@tanbro
tanbro / StringSplit.c
Created August 30, 2011 03:34
split char* into char*[]
/*
============================================================================
Name : StringSplit.c
Author :
Version :
Copyright :
Description : Hello World in C, Ansi-style
============================================================================
*/
@tanbro
tanbro / sample.py
Created March 28, 2012 06:55
Server-Sent Events feature for tornado webserver
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2011-8-29
@author: tanbro
'''
import os
@tanbro
tanbro / remove_linesep.py
Last active February 20, 2019 04:01
Remove line seperator in a text
"""
Remove line seperator in a text
"""
import re
REMOVE_LINESEP_RE = re.compile(r'(?P<c>[\S])([\r|\n]+)')
def remove_linesep(s): # type: (str)->str
return re.sub(REMOVE_LINESEP_RE, r'\g<c>', s.strip())
@tanbro
tanbro / remove_cjk_whitespace.py
Last active March 14, 2019 06:05
Remove whitespaces in UTF-8 CJK string, by regex
import re
HANZI = r'([\u4E00-\u9FFF]|[\u3400-\u4DBF]|[\U00020000-\U0002A6DF]|[\U0002A700-\U0002B73F]|[\U0002B740-\U0002B81F]|[\U0002B820-\U0002CEAF]|[\uF900-\uFAFF]|[\U0002F800-\U0002FA1F])'
CJK_WHITESPACE_REGEX = re.compile(r'(?P<c>[\u2E80-\u9FFF])(\s+)')
def remove_cjk_whitespace(s): # type: (str)->str
"""删除字符串中 CJK 文字之间的空格
@tanbro
tanbro / corenlp_ssplit.py
Last active March 21, 2019 08:31
使用 Web API 远程调用 CoreNLP Server 的 ssplit 进行分句和分词。
# -*- coding: utf-8 -*-
"""
使用 CoreNLP 进行汉语语料的分句和分词
"""
import os
import re
import unicodedata
import unittest
@tanbro
tanbro / remake_pyconly_wheel.py
Last active February 21, 2020 02:24
A small tool Re-Pack a Python Wheel to a PYC-Only One
# -*- coding: utf-8 -*-
"""
Re-Pack `Wheel` to a PYC-Only One
"""
from __future__ import print_function, unicode_literals
import argparse
import compileall
@tanbro
tanbro / singleinstance.py
Last active December 11, 2020 05:43
singleinstance
import sys
import os
try:
import fcntl
except ImportError:
fcntl = None
LOCK_PATH = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "lock")
OS_WIN = False
@tanbro
tanbro / namecase.py
Last active November 16, 2021 07:40
A python module snakelize or camelize string keys inside a dictionary
"""
Change dictionary's key naming style
"""
from typing import Iterable, Mapping
import stringcase
__all__ = ['convert', 'camelize', 'pascalize', 'snakelize']
#include <stddef.h>
#include <memory.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
/// 参考: https://www.openssl.org/docs/man1.0.2/man3/BIO_f_base64.html 以及
/// https://gist.github.com/barrysteyn/7308212