From 33ce2061dde239936060009dd0d600e2d38af903 Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Thu, 18 Sep 2025 09:09:13 +0900 Subject: [PATCH] clean bashrc --- .gitignore | 3 +- cpu-bench/{bench.py => Dockerfile} | 98 ++++++++++-------- cpu-bench/Makefile | 4 + linux-bash/bash_aliases.sh | 161 ++++++----------------------- zmq-sqlite/README.md | 33 ++++++ 5 files changed, 127 insertions(+), 172 deletions(-) rename cpu-bench/{bench.py => Dockerfile} (83%) create mode 100644 cpu-bench/Makefile create mode 100644 zmq-sqlite/README.md diff --git a/.gitignore b/.gitignore index 337d25d..1635eda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .ipynb_checkpoints -__pycache__ \ No newline at end of file +__pycache__ +cpu-bench/*.png diff --git a/cpu-bench/bench.py b/cpu-bench/Dockerfile similarity index 83% rename from cpu-bench/bench.py rename to cpu-bench/Dockerfile index 43be1b3..6e4cf94 100644 --- a/cpu-bench/bench.py +++ b/cpu-bench/Dockerfile @@ -1,43 +1,55 @@ -#!/usr/bin/env python - -def ensure(*packages): - for pkg in packages: - try: __import__(pkg) - except: import os; os.system(f'pip install -q {pkg}') -ensure('pandas', 'tabulate') - -import subprocess, multiprocessing as mp, warnings, pandas as pd -from tqdm.auto import tqdm -from tabulate import tabulate -warnings.filterwarnings("ignore") -R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) -subprocess.run('clear') -subprocess.run('neofetch') - -command = lambda core: f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second' - -print(f'{G}$ {command("$(nproc)")}{W}', flush=True) - - -def speed(core): - output = subprocess.run( - command(core), shell=True, capture_output=True, text=True - ).stdout.split()[-1] - return float(output) - -df = [] -for core in range(1, mp.cpu_count()+1): - s = speed(core) - row = { - '#Threads': core, - 'Throughput(/s)': s, - '(per-core)': s/core - } - df.append(row) -df = pd.DataFrame(df) -df.to_csv('result.csv', index=False) - -df.iloc[:, 0] = df.iloc[:, 0].apply(lambda s: f'{R}{s}{W}') -df.iloc[:, 1] = df.iloc[:, 1].apply(lambda s: f'{G}{int(s)}{W}') -df.iloc[:, 2] = df.iloc[:, 2].apply(lambda s: f'{B}{int(s)}{W}') -print(tabulate(df, headers='keys', tablefmt='rounded_outline', showindex=False)) +FROM python:slim + +RUN apt update && apt install -y sysbench fastfetch + +RUN pip install tqdm pandas tabulate + +RUN tee bench.py <> .gitignore - echo "Added directory: $item/ to .gitignore" - elif [ -f "$item" ]; then - echo "$item" >> .gitignore - echo "Added file: $item to .gitignore" - else - echo "Warning: $item does not exist" - fi - done -} - -alias r="redis-cli" -q() { "$@" > /dev/null 2>&1 & } diff --git a/zmq-sqlite/README.md b/zmq-sqlite/README.md new file mode 100644 index 0000000..9ca69fa --- /dev/null +++ b/zmq-sqlite/README.md @@ -0,0 +1,33 @@ +# Server +```python +def SQL(): + import sqlite3, hashlib, os; con = sqlite3.connect('.db', isolation_level=None) + sql = lambda q, *p: list(con.execute(q, p)) + if not os.path.exists('.db-blob') and os.mkdir('.db-blob') is None: + con.executescript('''PRAGMA journal_mode=WAL; + CREATE TABLE kv(k, v, t DEFAULT CURRENT_TIMESTAMP); + CREATE INDEX idx_kv_v ON kv(v); CREATE INDEX idx_kv_k_t ON kv(k,t DESC)''') + def setitem(_, filename, blob): + if not sql('SELECT 1 FROM kv WHERE v=?', sha1 := hashlib.sha1(blob).hexdigest()): + with open(f'.db-blob/{sha1}', 'xb') as f: f.write(blob) + sql('INSERT INTO kv(k,v) VALUES(?,?)', filename, sha1) + def getitem(_, filename): + if sha1 := sql('SELECT v FROM kv WHERE k=? ORDER BY t DESC', filename): + return open(f'.db-blob/{sha1[0][0]}', 'rb').read() + return type('', (), dict(__setitem__=setitem, __getitem__=getitem))() +sql = SQL() + +import zmq; (socket := zmq.Context().socket(zmq.REP)).bind('tcp://*:5555') +while True: + filename, blob = socket.recv_pyobj() + sql[filename] = blob + socket.send_string('OK') +``` + +# Client +```python +def put(filename, blob, addr='tcp://localhost:5555'): + import zmq; (socket := zmq.Context().socket(zmq.REQ)).connect(addr) + assert socket.send_pyobj((filename, blob)) or socket.recv_string() == 'OK' +put('hello', b'world') +``` \ No newline at end of file