Skip to content

Instantly share code, notes, and snippets.

@tanbro
tanbro / 单机多用户 JupyterLab 环境搭建.md
Last active April 28, 2024 13:58
单机多用户 JupyterLab 环境搭建

单机多用户 JupyterLab 环境搭建

概述

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

目标是:

  • 操作系统的用户可以各自不受干扰的使用独立的 [JupyterLab][]
  • 各个用户的 [Conda][] 环境可以自动的出现在 [JupyterLab][] 的 Kernel 列表中
@tanbro
tanbro / grab_source_files.py
Last active March 9, 2024 09:33
Export all source code files into a single HTML file with Pygments syntax highlight and remove all comments and empty lines.
#!/usr/bin/env python
"""
Export all source code files into a single HTML file with Pygments syntax highlight and remove all comments and empty lines.
"""
import argparse
import fnmatch
import os
import sys
@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 / snippetfuncexecutor.py
Created January 15, 2024 04:16
exec and eval a Python code snippet with return expression, as if it's in a non-arguments function
class SnippetFuncExecutor:
"""
exec and eval a Python code snippet with return expression, as if it's in a non-arguments function
"""
def __init__(
self,
*,
prefix: Optional[str] = None,
optimize: int = -1,
#!/usr/bin/env python3
"""
# Report PyProject version
The tool print python source code project's version from pip install report with a dry-run.
The project MUST have a `pyproject.toml` file with metadata defined in it!
- On non-western language Windows, environment `PYTHONUTF8` may be in need .
@tanbro
tanbro / caseconvert.py
Last active June 16, 2023 03:07
Change dictionary's key naming style
"""
Change dictionary's key naming style
"""
from typing import (
Any,
Callable,
Iterable,
Mapping,
MutableMapping,
@tanbro
tanbro / re_replace.h
Last active September 28, 2022 07:56
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 / make_manylinux_wheels.py
Last active August 3, 2022 07:13
使用 quay.io 提供的 pypa/manylinux Docker 镜像构建该项目及其依赖软件的 Python Wheel 发布包
#!/usr/bin/env python3
"""
使用 quay.io 提供的 pypa/manylinux Docker 镜像构建该项目及其依赖软件的 Python Wheel 发布包
"""
import argparse
import os
import os.path
import platform
@tanbro
tanbro / captchaimage.py
Last active July 15, 2022 07:37
Generate a captcha image
from itertools import product
from pathlib import Path
from random import choice, randint, randrange, uniform
from typing import Any, BinaryIO, Mapping, Optional, Sequence, Union
from PIL import Image, ImageDraw, ImageFilter, ImageFont
__all__ = ['captcha_image']