Skip to content

Instantly share code, notes, and snippets.

@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 / 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 {
@luochen1990
luochen1990 / nix-repl.expect
Last active May 30, 2022 13:49
A convient nix-repl to debug your nix flakes
#!/usr/bin/env nix-shell
#! nix-shell -p "expect" -i expect
#set timeout -1
cd ~/ws/nixos
spawn nix repl
send ":lf .\n"
@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 / nix-wrap
Last active February 23, 2022 07:12
nix-wrap: shebang to make your Nix file into executable
#!/usr/bin/env bash
#echo '$@ = ' "$@"
nixfile="$1"; shift
#echo "nixfile =" "$nixfile"
outpath="$(nix-build --pure $nixfile)"
#echo "outpath =" "$outpath"
@luochen1990
luochen1990 / puzzle.hs
Created February 14, 2022 10:07
logic puzzle
#!/usr/bin/env nix-shell
#! nix-shell -p "ghc"
#! nix-shell -i "runghc"
-- https://www.zhihu.com/question/23999095/answer/2254625328
import Control.Monad (guard)
brain_states :: (Int, Int) -> [Int]
brain_states (x, y) = [z | z <- [x + y, abs(x - y)], z > 0]
@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 / build.nix
Created January 30, 2022 10:24
用 Nix 构建 C 项目的最简配置示例
#!/usr/bin/env nix-build
{ nixpkgs ? (import <nixpkgs> {}) }: with nixpkgs;
stdenv.mkDerivation rec {
pname = "some-c-project";
version = "0.1";
src = ./.;
nativeBuildInputs = [ cmake ]; #replace to your build time dependencies
buildInputs = [ libssl ]; #replace to your runtime dependencies
}