Skip to content

Instantly share code, notes, and snippets.

print(’\033[31m\u2764‘ × 29)
@lucmann
lucmann / rename.sh
Last active November 13, 2019 03:10
rename files in batch
find . -name '*.crx' | sed "s;\(\.\/.*\)\.crx$;mv \1.crx \1.zip;" | bash
# A simpler solution
find . -type f | xargs -I{} sh -c "mv {} {}.zip"
@lucmann
lucmann / .bashrc
Created November 17, 2019 07:50
alias for git
alias ga="git status -s | grep '^ M' | awk '{print \$2}' | xargs git add" # dont add the new files
@lucmann
lucmann / calc_mipmap.py
Created December 5, 2019 03:58
one line to calculate the sum of POT
sum(x for x in list(map(lambda n: 2**n * 2**n, range(13))))
#!/usr/bin/env python
import argparse
class LargeFileSplitter:
def __init__(self, file, n):
self.file = file
self.num = n
if file.endswith('.txt'):
file = file[:-4]
@lucmann
lucmann / md2pdf.sh
Created December 8, 2021 09:44
convert markdown to pdf with pandoc
#!/usr/bin/env bash
PREFERRED_FONT="AR PL KaitiM GB"
CJK_MAIN_FONT=
zh_fonts_file=$(mktemp -t fonts.XXX)
# save fonts family into a temp file to avoid the trouble with spaces among font family string
fc-list :lang=zh --format "%{family[0]}\n" > $zh_fonts_file
if [[ ! -s $zh_fonts_file ]]; then
@lucmann
lucmann / rename_in_bulk.sh
Created December 28, 2021 04:44
rename files in bulk
find -name 'ARB-*.md' -printf '%P\n' | awk '{orig=$0; gsub(/-/, "_"); print "mv", orig, $0}' | bash
# notes
#
# -printf '%P\n' to strip preceding './' from find's output
# orig=$0 to save original file name
# gsub(/-/, "_") to subsititue '-' in the original file name to '_' in the target file name, it happens to '$0' in place
# print "mv", orig, $0 to generate shell command
echo "#include <stdio.h>\nint main() { int a = sizeof(struct {}); printf(\"a = %d\\\n\", a); }" | gcc -x c -
# a = 0
echo "#include <stdio.h>\nint main() { int a = sizeof(struct {}); printf(\"a = %d\\\n\", a); }" | gcc -x c++ -
# <stdin>:2:36: error: types may not be defined in ‘sizeof’ expressions
@lucmann
lucmann / lkcn.sh
Created May 13, 2024 07:28
linux kernel codename
git log -L"/^VERSION = /,/^NAME = /:Makefile" --pretty="%h" --no-patch |
while read revision; do git show "$revision":Makefile |
sed -n -e '/^VERSION = [0-9]/ { N; N; N; N; s/\n/ /g; p }' |
sed -e 's/VERSION = //' -e 's/ PATCHLEVEL = /./' -e 's/ SUBLEVEL = /./' -e 's/ EXTRAVERSION = *//' -e 's/NAME/ NAME/'; done
@lucmann
lucmann / .muttrc
Last active May 28, 2024 01:16
mutt config
set from="luc@sietium.com"
set realname="Luc Ma"
# ==================== IMAP =============================
set imap_user = "onion0709@gmail.com"
# git-send-email
# set imap_pass = "xxxx xxxx xxxx xxxx"