Skip to content
oakkitten edited this page Apr 12, 2021 · 4 revisions

Limit network speed for a port

Usage: limit-port-speed 9000, unlimit-port-speed. For loopback device, use lo

limit-port-speed() {
  tc qdisc add dev eth0 root handle 1: prio
  tc filter add dev eth0 parent 1: protocol ip basic match "cmp(u16 at 0 layer transport eq $1)" action police rate 100kbit burst 10k
  tc qdisc add dev eth0 ingress
  tc filter add dev eth0 ingress protocol ip basic match "cmp(u16 at 2 layer transport eq $1)" action police rate 100kbit burst 10k
}
unlimit-port-speed() {
  tc qdisc del dev eth0 root
  tc qdisc del dev eth0 ingress
}

Simulate socket timeout

To drop packets coming out from port 9000, and then to clear rules:

iptables -A OUTPUT -p tcp --sport 9000 -j DROP
iptables -F

Git aliases

Delete a branch but keep a reference to in

Usage: git ghost branch

ghost = "!f() { \
    git update-ref refs/ghosts/\"$1\" refs/heads/\"$1\" "" && \
    git update-ref -d refs/heads/\"$1\"; \
}; f"

Find commit by play store apk name

Usage: git nth 637

nth = "!f() { \
    [[ $1 =~ ^[0-9]+$ ]] && \
    skip=$(($(git rev-list master --first-parent --count) - 10#$1)) \
    && (( skip >= 0 )) && \
    git log --skip=$skip --max-count=1 --first-parent master; \
}; f"

Put current changes into a commit on a separate branch

Usage: git aside, git aside branch-name. Like git stash, but makes a regular commit

aside = "!f() { \
    if [[ -z \"$(git status --porcelain)\" ]]; then \
        echo 'working directory clean'; return; \
    fi; \
    \
    branch=\"$(git rev-parse --abbrev-ref HEAD)\"; \
    if [[ -z \"$branch\" ]]; then \
        echo 'bad branch'; return; \
    fi; \
    \
    if [[ -z \"$1\" ]]; then \
        for i in {0..20}; do \
            aside=\"$branch-$i\"; \
            git show-ref --verify --quiet refs/heads/\"$aside\" || break; \
        done; \
    else \
        aside=\"$1\"; \
    fi; \
    if git checkout -b \"$aside\"; then \
        git add -A && git commit; \
        committed=$?; \
        git checkout \"$branch\"; \
        (( $committed != 0 )) && git branch -d \"$aside\"; \
    fi; \
}; f"

Spell check currently modified files

Assuming strings.xml and French, run git diff | vim -, then:

:hi clear SpellBad
:hi SpellBad cterm=reverse
:setlocal syntax=xml
:set spell spelllang=fr_fr
:syn region xmlString contained start=+'+ end=+'+ contains=xmlEntity,@NoSpell display
:syn region xmlString contained start=+"+ end=+"+ contains=xmlEntity,@NoSpell display
:syn spell toplevel
:redraw

Simulate activity in WeeChat

Add an alias

/alias add flood /eval /trigger addreplace message1_${buffer} timer 1496\;0\;0 "" "" "/print -buffer ${buffer.full_name} ${buffer} Lorem ipsum dolor sit amet, consectetur adipiscing elit";/eval /trigger addreplace message2_${buffer} timer 496\;0\;0 "" "" "/print -buffer ${buffer.full_name} ${buffer} Nam tincidunt lorem nibh";/eval /trigger addreplace highlight_${buffer} timer 5128\;0\;0 "" "" "/print -tags notify_highlight -buffer ${buffer.full_name} ${buffer} Highlight!"

Then open a few private windows and start a deluge of messages in them

/query Lorem,ipsum,dolor,sit,amet,consectetur,adipiscing,elit,sed,do,eiusmod,tempor,incididunt,ut,labore
/allpv /flood

To stop, run

/trigger del -all