Skip to content

Instantly share code, notes, and snippets.

@braindevices
braindevices / CoW_podman-docker_mounted_volume.md
Created September 3, 2024 20:41
reflink can directly work with mounted volumes if the volumes are on the same host partition

reflink in mounted volume

podman run -v /data/devspace/dummy/test/A:/mnt/A:Z -v /data/devspace/dummy/test/B:/mnt/B:Z --rm -it ubuntu:latest /bin/bash

following works fine

root@68ec02c9b450:/mnt# cp --reflink=always A/test10M.bin A/reflinked.bin
[dummy@host test]$ xfs_io -r -c 'fiemap' A/reflinked.bin 
@braindevices
braindevices / xfs-cow-vs-btrfs-cow.md
Last active August 17, 2024 22:51
XFS reflinks vs btrfs snapshots

XFS reflinks vs BTRFS snapshots

reflinks in XFS

reflinks can be used as CoW mechanism for XFS since 4.17.0-2.el8

This feature enables two or more files to share a common set of data blocks. When either of the files sharing common blocks changes, XFS breaks the link to common blocks and creates a new file.

so with cp --reflink we can create CoW blocks already. This is similar to btrfs CoW. We can simply do following to mimic the snapshot:

find /root -mindepth 1 -maxdepth 1 -not -name "backup" -exec cp -r --reflink {} /root/backup/$(date)/ ;
@braindevices
braindevices / cal_yolov8_rf.py
Last active June 30, 2024 01:05
receptive field of yolov8
# each bottleneck blcok has 4 conv that k>1
btn = [(3,1)]*4
# stem, C1 (1), C2 (2), conv, C3 (4), conv, C4 (6), conv, C2f, C5 (SPPF) (9)
idx_Cs = [1,2,4,6,9]
blocks = [
[(3,2)], # conv
[(3,2)], # conv
btn*1, # C2f n=3*d
[(3,2)], # conv
btn*2, # C2f n=6*d
@braindevices
braindevices / systemd-timer-restart-bug.sh
Last active December 20, 2023 17:39
strange systemd timer bug: restart the timer trigger the unit run
#!/bin/bash
set -x
systemctl -T -o verbose daemon-reload
systemctl -T -o verbose disable --now test-timer.timer
set -e
wait_secs=20
run_at_time=$(date -d "+${wait_secs}sec" +"%H:%M:%S")
logfile=/tmp/test-timer-output
if [ -f ${logfile} ]
then
@braindevices
braindevices / how_docker_firewalld_libvirt_implement_rules.md
Last active November 4, 2023 19:25
how lbvirt/docker interact weith firewalld

docker just do not get along with libvirt, iptables, nptables, firewalld, etc

why my container isolation comes and gos? iptables, nptables, firewalld, who did what?!

there is almost NOT legacy iptables command (iptables) on modern OS (RHEL8, ubuntu22, etc) there can still be some lagecy ip_tables module loaded:

lsb_release -d; lsmod | grep tables; iptables -V
Description:    Fedora release 38 (Thirty Eight)
nf_tables             368640  1454 nft_compat,nft_chain_nat
nfnetlink              20480  8 nft_compat,nfnetlink_acct,nf_conntrack_netlink,nf_tables,ip_set
Description:    Red Hat Enterprise Linux release 8.8 (Ootpa)
@braindevices
braindevices / auto_textwrap_in_pandas_styler.md
Created February 14, 2023 21:47
how to autowrap the text in excel when export from pandas dataframe styler

The styler gives us a easy way to format the dataframe and maintain the format across different kind of output: html, excel, etc.

However, one of my friends has spot a problem of it, the styler.to_excel() output some how supressed some advanced formating of XlsxWriter. Here is an example:

import pandas as pd
data = pd.DataFrame({"A":list(range(10,12)), "B":["abcdefgafafadf", "afbafafafafadfadfadf"]})
with pd.ExcelWriter("/tmp/test.xlsx") as writer:
    data.style.apply(lambda x: ['background-color: red']*2 if x['A']==11 else [None]*2, axis=1).to_excel(writer, index=False)
 writer.sheets["Sheet1"].write(3, 1, "Some long text to wrap in a cell")
@braindevices
braindevices / #btrfs benchmark for daily used desktop OS
Last active December 28, 2024 02:51
which file sytem to use for daily work? should we turn on btrfs compression?
#btrfs benchmark for daily used desktop OS
1–10 11–20 20–30
6940 5839 6007
6615 6957 6314
6169 6877 6224
6142 6324 6210
6492 6685 6961
6908 5964 6475
@braindevices
braindevices / dnsmasq-gfwlist.py
Created May 31, 2017 17:58 — forked from lanceliao/dnsmasq-gfwlist.py
将gfwlist转换成带ipset的dnsmasq规则,适用于OpenWrt智能上网
#!/usr/bin/env python
#coding=utf-8
#
# Generate a list of dnsmasq rules with ipset for gfwlist
#
# Copyright (C) 2014 http://www.shuyz.com
# Ref https://code.google.com/p/autoproxy-gfwlist/wiki/Rules
import urllib2
import re
@braindevices
braindevices / get_tushare_data.py
Created April 10, 2017 16:46 — forked from xgdgsc/get_tushare_data.py
get tushare data
# coding: utf-8
import tushare as ts
import pandas as pd
import pickle
stock_list = ts.get_stock_basics()
# In[ ]: