Skip to content

Instantly share code, notes, and snippets.

@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 / re_replace.h
Last active May 16, 2024 01:25
str replace and regex replace functions in C language
#ifndef __RE_REPLACE__
#define __RE_REPLACE__
#include <string.h>
#include <regex.h>
#ifdef __cplusplus
extern "C" {
#endif
@tanbro
tanbro / attrdict.py
Last active January 17, 2024 14:51
A class with both dictionary and attribute style access to it's data member.
from __future__ import annotations
from typing import Any, Dict, Iterable, Mapping, MutableMapping, MutableSequence, Union
class AttrDict:
"""
A class with both dictionary and attribute style access to it's data member.
It can be used in `RestrictedPython <http://restrictedpython.readthedocs.io/>`_
@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 / 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 / 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 / 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 / 单机多用户 JupyterLab 环境搭建.md
Last active September 29, 2024 02:00
单机多用户 JupyterLab 环境搭建

单机多用户 JupyterLab 环境搭建

概述

在这篇短文中,我们记录了如何在使用 [Ubuntu][] 1804 LTS 操作系统的单台服务器上,建立用户隔离的 [JupyterLab][] Web 环境。

目标是:

  • 操作系统的用户可以各自不受干扰的使用独立的 [JupyterLab][]
  • 各个用户的 [Conda][] 环境可以自动的出现在 [JupyterLab][] 的 Kernel 列表中
@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())