Skip to content

Instantly share code, notes, and snippets.

@luochen1990
luochen1990 / venv-py37.nix
Last active March 29, 2024 12:18
Nix Script to simulate FHS environment with python3 & pip & venv
#!/usr/bin/env -S bash -c 'nix-shell --pure $0 -A env'
# Usage:
# 1. run directly to enter bash (inside venv): `./venv-py37.nix`
# 2. build a standalone executable: `nix bundle -f ./venv-py37.nix` #this not works yet since it cause nested `unshare -U` call
# 3. run bash with extra arguments: `nix run -f ./venv-py37.nix '' -- -c 'python --version'`
# More:
# 1. commit id of nixpkgs can be found here: https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=python3
let
@luochen1990
luochen1990 / im-custom-phrases.py
Last active December 13, 2023 08:47
在输入法(Input Method) 中通过自定义短语输入数学符号, 该脚本用以生成相关配置文件
#!/usr/bin/env python3
phrases = '''
; 希腊字母: 参考 https://en.wikipedia.org/wiki/Greek_alphabet
Alpha,1=Α
alpha,1=α
Nu,9=Ν
nu,9=ν
Beta,1=Β
@luochen1990
luochen1990 / JsonHelper.java
Created June 17, 2020 05:00
Gson custom TypeAdapter (including serialization and deserialization) for Generic Types like Optional/List
package tools;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import io.vavr.collection.List;
import io.vavr.control.Option;
import java.io.IOException;
@luochen1990
luochen1990 / bad-whitespace-example.txt
Last active September 25, 2023 07:52
团队协作的场景下, 需要对团队成员的git使用方式有一定的要求, 以保证协作的畅通和高效.
hello
tab indent
space indent
tab indent with following space
space before tab
space at eol (trailing-space)
tab at eol (trailing-space)
blank at eof (also trailing-space)
@luochen1990
luochen1990 / merge_pdf.py
Created September 13, 2023 10:09
合并多个 pdf 文件
#!/usr/bin/env nix-shell
#!nix-shell -i python --packages python311 python311Packages.pypdf2
import PyPDF2
def merge_pdfs(input_path_list: list[str], output_path: str):
pdfWriter = PyPDF2.PdfWriter()
for input_path in input_path_list:
pdf1 = PyPDF2.PdfReader(open(input_path, "rb"))
@luochen1990
luochen1990 / settings.json
Created August 22, 2023 04:54
VSCode Python strict mode config
{
"files.trimTrailingWhitespace": true,
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "strict",
"python.analysis.diagnosticSeverityOverrides": {
"reportImportCycles": "warning",
"reportUnnecessaryComparison": "information",
"reportUnnecessaryIsInstance": "information",
"reportUnnecessaryContains": "information",
"reportUnusedImport": "information",
@luochen1990
luochen1990 / PhraseEdit.txt
Last active July 31, 2023 01:19
搜狗输入法 - 数学&逻辑符号输入设置
; 搜狗输入法: 设置 -> 高级 -> 自定义短语设置 -> 直接编辑配置文件
;  配置文件格式: <按键序列> "逗号" <位置> "等于号" <目标字符序列>
; 希腊字母: 参考 https://en.wikipedia.org/wiki/Greek_alphabet
Alpha,1=Α
alpha,1=α
Nu,9=Ν
nu,9=ν
@luochen1990
luochen1990 / shell.nix
Created February 14, 2022 08:49
(示例) 在 NixOS 中构建可用 pip 的 python 隔离环境
#!/usr/bin/env nix-shell
#! nix-shell shell.nix
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
name = "devbox";
targetPkgs = pkgs: (with pkgs; [
python38
python38Packages.pip
@luochen1990
luochen1990 / popo.nix
Last active October 19, 2022 05:47
(wip) netease popo
#NOTE: not working yet, need debuging
{pkgs ? import <nixpkgs> {}, ...}:
pkgs.stdenv.mkDerivation rec {
pname = "popo";
version = "3.56.1";
src = pkgs.fetchurl {
url = "https://popo.netease.com/file/popolinux/popo_${version}_amd64_ubuntu.deb";
@luochen1990
luochen1990 / flake.nix
Created July 7, 2022 14:42
An easy Haskell develop environment (useage: nix develop)
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
hpkgs = pkgs.haskell.packages.ghc923;
in rec {