Skip to content

Instantly share code, notes, and snippets.

View ouuan's full-sized avatar

Yufan You ouuan

View GitHub Profile
@ouuan
ouuan / .atoolrc
Created March 26, 2022 09:23
Windows 下压缩的文件 unzip 中文乱码
path_unzip /home/ouuan/scripts/unzip-cp936.sh
@ouuan
ouuan / translate.sh
Last active April 20, 2024 11:07
Xorg (Linux) 任意窗口划词翻译
#!/bin/bash
# X.Org 任意窗口划词翻译
# 在 DE/WM 中设置快捷键执行
# 分单词和句子两种模式,notification 中显示的都是 Google 翻译的结果,但单词附带百度翻译的链接,句子附带 Google 翻译的链接
# notification 中附带的链接是否能点开依赖于 notification daemon,dunst 需要在设置中的 `mouse_left_click` 处加上 `open_url`
# 翻译的单词连同日期和窗口标题会记录在 ~/.cache/translated-words.txt
# 可以使用 http_proxy 环境变量设置代理
# notification 的 appname 是 "xorg-translate",在 dunst 中可以对其进行配置,例如设置图标
#
@ouuan
ouuan / autopause.sh
Last active June 18, 2021 07:15
Auto-pause players on pulseaudio sink remove
#!/bin/bash
LANG=C pactl subscribe | grep --line-buffered "Event 'remove' on sink" | xargs -L1 playerctl -a pause
@ouuan
ouuan / take-a-break.sh
Last active May 1, 2021 02:55
Take a break from your Xorg session
#!/bin/bash
# In <duration> seconds, if you have been unlocked for more than <permit> seconds, you'll be locked;
# if you have been unlocked for more than <warning> seconds, you'll be asked to lock every <dialoginterval> seconds.
# The stats are saved at <file>.
duration=3600
permit=3200
warning=2800
dialoginterval=180
@ouuan
ouuan / track-window.sh
Last active April 10, 2021 17:57
Track time-usage for Xorg windows
#!/bin/bash
file="$HOME/.track-window-stats"
period=1
while true
do
locked=$(loginctl show-session "$XDG_SESSION_ID" -p LockedHint --value)
if [[ "$locked" == 'yes' ]]; then
result='<locked>'
@ouuan
ouuan / concat_original_video_and_reversed_video.sh
Last active August 25, 2020 14:36
Concat original video and reversed video
origin_reversed() {
local tmp_dir=/tmp/concat_original_video_and_reversed_video
local base_name=$(basename "$1")
local mts_path="$tmp_dir/${base_name}.mts"
local reversed_path="$tmp_dir/${base_name}-reversed.mts"
local concat_path="$tmp_dir/${base_name}-concat.mts"
local list_path="$tmp_dir/${base_name}-list"
mkdir -p "$tmp_dir"
ffmpeg -i "$1" -q 0 "$mts_path"
ffmpeg -i "$mts_path" -vf reverse -af areverse "$reversed_path"
@ouuan
ouuan / math.sh
Last active October 22, 2021 07:39
Do math in the terminal!
# add this in ~/.zshrc
math() {
local MATH_RESPONSE
case $(($RANDOM % 3)) in
0)
local MATH_A=$(($RANDOM % 10000))
local MATH_B=$(($RANDOM % 10000))
read "MATH_RESPONSE?$MATH_A + $MATH_B = "
local MATH_ANSWER=$(($MATH_A + $MATH_B))
@ouuan
ouuan / yay_cd.sh
Last active June 8, 2021 13:24
Get rid of your yay addiction
# https://gist.github.com/ouuan/c88295eea5dd89feecd712e8005d9dfa
# the package dateutils is required for the datediff command
# $1: the command
# $2: the short name of the command
# $3: the command to eval when it's in cd
# $COMMAND_CD_PATH: the path to save the cd time, default is $HOME/.command_cd_<short name or full command>
# $COMMAND_CD_LENGTH: cd length in nanoseconds, default is one hour
command_cd() {
@ouuan
ouuan / transfer.sh
Last active October 22, 2021 07:38
将 namex-x.in 格式的数据改成 namex.in 格式的,输出 UOJ 格式的 subtask_end
ls *.in | sort -V | awk '{
begin = match($0, /-[0-9]*/) + 1;
if (substr($0, begin, RLENGTH - 1) == "1") {
if (subtask > 0) print "subtask_end_" subtask " " NR - 1 ;
++subtask;
if (!getline line) print "subtask_end_" subtask " " NR;
}
}'
ls *.in | sort -V | awk '{tmp = $0; gsub(/[0-9]*-[0-9]*/, NR); system("cp " tmp " " $0);}'
ls *.out | sort -V | awk '{tmp = $0; gsub(/[0-9]*-[0-9]*/, NR); system("cp " tmp " " $0);}'
@ouuan
ouuan / cat.html
Last active October 15, 2019 06:16
Huawei Honorcup Marathon 2 (https://codeforces.com/contest/1235)
<head>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
var answer = [];
var cur = 0;
var lastX = -1;
var lastY = -1;
var answerStr = '';
function drawBlock(x, y) {