From 896878fef68b0bbd27ca820db7704606d3e9fb02 Mon Sep 17 00:00:00 2001 From: Kevin Mok Date: Wed, 23 Jan 2019 19:58:34 -0500 Subject: [PATCH] Added qr-gif and rick-roll scripts Also added 369 and internet aliases. --- aliases/zsh_aliases | 16 ++++++++ configs/i3/config | 5 ++- dotfiles/.bashrc | 1 + dotfiles/.vimrc | 6 ++- scripts/qr-gif.sh | 52 ++++++++++++++++++++++++ scripts/rick-roll | 98 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 176 insertions(+), 2 deletions(-) create mode 100755 scripts/qr-gif.sh create mode 100755 scripts/rick-roll diff --git a/aliases/zsh_aliases b/aliases/zsh_aliases index 7bc2360..ca5fa5a 100644 --- a/aliases/zsh_aliases +++ b/aliases/zsh_aliases @@ -148,6 +148,11 @@ alias xpc="pacman -Qqe > ~/linux-config/txt/pacman-pkgs/nzxt-pkgs.txt" # alias tri="trizen -S --noconfirm" alias tri="trizen -S" +# internet +alias pg="ping -c 3 8.8.8.8" +alias dh="sudo dhcpcd" +alias rdh="sudo killall dhcpcd && sudo dhcpcd" + # }}} system # # config files {{{ # @@ -179,6 +184,7 @@ function ev() { nohup evince $1 > /dev/null 2>&1& ; } function chr() { google-chrome $1 ; } alias n="nvim" alias sni="sudo nvim" +alias fh="feh --bg $wallpaper" function mrk() { pandoc -o ${1%.*}.html $1 ; } alias wp="grep wallpaper ~/.cache/wal/colors.sh" @@ -391,3 +397,13 @@ alias tcl="tex-clean" # }}} coding projs # +# school {{{ # + +# 369 +alias vm6="VBoxHeadless --startvm 369-a1" +alias sha="ssh kevin@192.168.0.21" +alias cpi="scp interceptor.c kevin@192.168.0.21:/home/kevin/a1" +alias ma="make" +alias mc="make clean" + +# }}} school # diff --git a/configs/i3/config b/configs/i3/config index 6104222..d6fb77f 100644 --- a/configs/i3/config +++ b/configs/i3/config @@ -32,6 +32,7 @@ bindsym Mod4+a exec studio bindsym $mod+control+Return exec $def_term bindsym Mod4+c exec $browser bindsym Mod4+f exec firefox +bindsym Mod4+$mod+f exec echo 'Kevin@fosstodon.org' | xclip -selection clipboard bindsym Mod4+h exec echo 'kevin.mok@live.ca' | xclip -selection clipboard bindsym Mod4+n exec urxvt -e nvim bindsym Mod4+o exec xclip -selection clipboard ~/.password-store/social/gmail @@ -42,7 +43,8 @@ bindsym Mod4+q exec qdirstat bindsym Mod4+r exec urxvt -e ranger # bindsym control+$mod+s exec systemctl suspend bindsym control+$mod+s exec systemctl suspend -bindsym Mod4+t exec st +# bindsym Mod4+t exec st +bindsym Mod4+t exec xclip -selection clipboard ~/.password-store/social/trapbot bindsym Mod4+u exec echo 'kevin.mok@mail.utoronto.ca' | xclip -selection clipboard bindsym Mod4+$mod+u exec pass -c uoft/acorn @@ -51,6 +53,7 @@ bindsym Mod4+$mod+u exec pass -c uoft/acorn bindsym Mod4+z exec cliqz # bindsym Print exec gscreenshot bindsym Print --release exec "scrot -s /tmp/screenshot-$(date +%F_%T).png -e 'xclip -selection c -t image/png < $f'" +bindsym control+Print --release exec "scrot -u /tmp/screenshot-$(date +%F_%T).png -e 'xclip -selection c -t image/png < $f'" # }}} app shortcuts # # redshift {{{ # diff --git a/dotfiles/.bashrc b/dotfiles/.bashrc index 1f0e20c..348493e 100644 --- a/dotfiles/.bashrc +++ b/dotfiles/.bashrc @@ -203,5 +203,6 @@ then else xrandr --dpi 150 fi +# Both PC/Laptop }}} [ -f ~/.fzf.bash ] && source ~/.fzf.bash diff --git a/dotfiles/.vimrc b/dotfiles/.vimrc index 3be2b88..a2b9182 100644 --- a/dotfiles/.vimrc +++ b/dotfiles/.vimrc @@ -35,7 +35,10 @@ set noswapfile autocmd VimResized * wincmd = autocmd BufNewFile,BufRead .* set syntax=sh -autocmd Filetype css,htmldjango,html,tex,txt,markdown set tabstop=2 shiftwidth=2 expandtab +filetype plugin on +filetype indent on +autocmd FileType css,htmldjango,html,tex,markdown set tabstop=2 shiftwidth=2 expandtab +autocmd BufNewFile,BufRead *.txt set tabstop=2 shiftwidth=2 expandtab autocmd BufRead commit-msg.txt set filetype=gitcommit tw=72 autocmd BufNewFile,BufRead *.md set filetype=markdown autocmd Filetype markdown set textwidth=0 @@ -168,6 +171,7 @@ colorscheme wal " Mappings {{{ " " function keys {{{ " +map :silent !scp %:p kevin@192.168.0.21:/home/kevin/a1 map :xa map :q! " map :make -C ~/Documents/resume cv diff --git a/scripts/qr-gif.sh b/scripts/qr-gif.sh new file mode 100755 index 0000000..5e4367d --- /dev/null +++ b/scripts/qr-gif.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# https://github.com/yishilin14/asc-key-to-qr-code-gif + +# Check requirements +hash qrencode 2>/dev/null || { echo >&2 "Aborting: qrencode not installed"; exit 1; } + +# Check argument +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi +asc_filename=$1 +if [ ! -f ${asc_filename} ]; then + echo "Error: ${asc_filename} not found" + exit 1 +fi + +# Settings +gif_filename=$2 +gif_delay=100 +qrcode_size=1732 +qrcode_version=30 + +# Split the file +rm -f ${asc_filename}.split* +split -b ${qrcode_size} ${asc_filename} ${asc_filename}.split + +# Generate png +for f in ${asc_filename}.split*; do + qrencode -v ${qrcode_version} -o $f.png < $f + rm $f +done + +if hash zbarimg 2>/dev/null; then + # Check png + > ${asc_filename}.scanned + for f in ${asc_filename}.split*; do + printf %s "$(zbarimg --raw -q $f)" >> ${asc_filename}.scanned + done + printf %s "$(cat ${asc_filename})" | diff ${asc_filename}.scanned - + rm ${asc_filename}.scanned +else + echo "Skip testing: zbarimg nout installed" +fi + +# Convert to gif +convert -delay ${gif_delay} ${asc_filename}.split* ${gif_filename} +echo "Generated: ${gif_filename}" + +# Clean up png +rm ${asc_filename}.split* + diff --git a/scripts/rick-roll b/scripts/rick-roll new file mode 100755 index 0000000..9603e19 --- /dev/null +++ b/scripts/rick-roll @@ -0,0 +1,98 @@ +#!/bin/bash +# Rick Astley in your Terminal. +# By Serene Han and Justine Tunney <3 +version='1.1' +rick='http://keroserene.net/lol' +video="$rick/astley80.full.bz2" +# TODO: I'll let someone with mac or windows machine send a pull request +# to get gsm going again :) +audio_gsm="$rick/roll.gsm" +audio_raw="$rick/roll.s16" +audpid=0 +NEVER_GONNA='curl -s -L http://bit.ly/10hA8iC | bash' +MAKE_YOU_CRY="$HOME/.bashrc" +red='\x1b[38;5;9m' +yell='\x1b[38;5;216m' +green='\x1b[38;5;10m' +purp='\x1b[38;5;171m' +echo -en '\x1b[s' # Save cursor. + +has?() { hash $1 2>/dev/null; } +cleanup() { (( audpid > 1 )) && kill $audpid 2>/dev/null; } +quit() { echo -e "\x1b[2J \x1b[0H ${purp}<3 \x1b[?25h \x1b[u \x1b[m"; } + +usage () { + echo -en "${green}Rick Astley performs ♪ Never Gonna Give You Up ♪ on STDOUT." + echo -e " ${purp}[v$version]" + echo -e "${yell}Usage: ./astley.sh [OPTIONS...]" + echo -e "${purp}OPTIONS : ${yell}" + echo -e " help - Show this message." + echo -e " inject - Append to ${purp}${USER}${yell}'s bashrc. (Recommended :D)" +} +for arg in "$@"; do + if [[ "$arg" == "help"* || "$arg" == "-h"* || "$arg" == "--h"* ]]; then + usage && exit + elif [[ "$arg" == "inject" ]]; then + echo -en "${red}[Inject] " + echo $NEVER_GONNA >> $MAKE_YOU_CRY + echo -e "${green}Appended to $MAKE_YOU_CRY. <3" + echo -en "${yell}If you've astley overdosed, " + echo -e "delete the line ${purp}\"$NEVER_GONNA\"${yell}." + exit + else + echo -e "${red}Unrecognized option: \"$arg\"" + usage && exit + fi +done +trap "cleanup" INT +trap "quit" EXIT + +# Bean streamin' - agnostic to curl or wget availability. +obtainium() { + if has? curl; then curl -s $1 + elif has? wget; then wget -q -O - $1 + else echo "Cannot has internets. :(" && exit + fi +} +echo -en "\x1b[?25l \x1b[2J \x1b[H" # Hide cursor, clear screen. + +#echo -e "${yell}Fetching audio..." +if has? afplay; then + # On Mac OS, if |afplay| available, pre-fetch compressed audio. + [ -f /tmp/roll.s16 ] || obtainium $audio_raw >/tmp/roll.s16 + afplay /tmp/roll.s16 & +elif has? aplay; then + # On Linux, if |aplay| available, stream raw sound. + obtainium $audio_raw | aplay -Dplug:default -q -f S16_LE -r 8000 & +elif has? play; then + # On Cygwin, if |play| is available (via sox), pre-fetch compressed audio. + obtainium $audio_gsm >/tmp/roll.gsm.wav + play -q /tmp/roll.gsm.wav & +fi +audpid=$! + +#echo -e "${yell}Fetching video..." +# Sync FPS to reality as best as possible. Mac's freebsd version of date cannot +# has nanoseconds so inject python. :/ +python <(cat < 0.0: + time.sleep(repose) + next_frame = elapsed / time_per_frame + if frame >= next_frame: + buf += line +except KeyboardInterrupt: + pass +EOF +) < <(obtainium $video | bunzip2 -q 2> /dev/null)