Skip to content

Instantly share code, notes, and snippets.

@binshengliu
binshengliu / backup with apt.txt
Created April 3, 2012 05:51 — forked from bepcyc/backup with apt.txt
BAckup and restore with aptitude in Ubuntu or Debian
before backup:
dpkg --get-selections > packages.txt
while restoring:
dpkg --clear-selections
dpkg --set-selections < packages.txt
aptitude install
@binshengliu
binshengliu / cornell-note.tex
Created August 15, 2017 15:12
Cornell-note latex template
% https://tex.stackexchange.com/a/273223/124998
\documentclass[a4paper]{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\title{
\vspace{-3em}
\begin{tcolorbox}[colframe=white,opacityback=0]
\begin{tcolorbox}
#
# STL GDB evaluators/views/utilities - 1.03
#
# The new GDB commands:
# are entirely non instrumental
# do not depend on any "inline"(s) - e.g. size(), [], etc
# are extremely tolerant to debugger settings
#
# This file should be "included" in .gdbinit as following:
# source stl-views.gdb or just paste it into your .gdbinit file
@binshengliu
binshengliu / fix-mp3.sh
Created August 29, 2021 00:42
Fix mp3 duration and encoding
# https://askubuntu.com/a/1000020/657385
ffmpeg -i file_orig.mp3 -acodec copy file_fixed.mp3
# https://www.xmodulo.com/convert-mp3-id3-tag-encodings-linux.html
mid3iconv -e gbk/big5 -d input.mp3
@binshengliu
binshengliu / unzip_zh.sh
Last active July 18, 2021 05:20
Unzip files with Chinese characters
# https://unix.stackexchange.com/a/501546/215915
env LC_ALL=zh_CN.GB2312 7z x file.zip
convmv -f zh_CN.GB2312 -t UTF8 -r .
@binshengliu
binshengliu / watermark.sh
Created June 26, 2021 00:15
Watermark a photo using command line
convert passport.jpg -background transparent -fill black -size 1024x256 -pointsize 24 -gravity center -annotate +0+205 'For ... Purpose' passport-water.jpg
@binshengliu
binshengliu / full-backup.sh
Last active May 17, 2021 00:01
Full System Backup
# https://wiki.archlinux.org/title/Rsync#Full_system_backup
rsync -aAXHv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup
# More human readable
rsync -aAXHh --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup
@binshengliu
binshengliu / beamer-notes-second-screen.tex
Created March 23, 2021 22:54
Show beamer notes on second screen
% https://tex.stackexchange.com/a/84763/124998
\usepackage{pgfpages}
\setbeameroption{show notes}
\setbeameroption{show notes on second screen=right}
% Command line:
% pdfpc --notes=right presentation.pdf
@binshengliu
binshengliu / pdf-to-png.sh
Created March 22, 2021 10:52
Convert PDF to PNG
# https://askubuntu.com/a/50180
pdftoppm -png -r 300 input.pdf png/out
@binshengliu
binshengliu / len_to_mask.py
Last active August 13, 2020 01:43
Convert different lengths into mask tensor
# lens = [3, 5, 4]
# What we want:
# mask = [[1, 1, 1, 0, 0],
# [1, 1, 1, 1, 1],
# [1, 1, 1, 1, 0]]
# https://stackoverflow.com/questions/53403306/how-to-batch-convert-sentence-lengths-to-masks-in-pytorch
def len_to_mask(lens: np.ndarray, seq_len: Optional[int] = None) -> np.ndarray:
if seq_len is None:
seq_len = max(lens)