Skip to content

Instantly share code, notes, and snippets.

@photonxp
photonxp / lns_multi_cwd.bash
Last active October 24, 2018 07:54
Make links in current working directory. A "ln -s" wrapper.
#!/bin/bash
# How can we eat the fish any more once we can read their minds? -- The dolphin lady
# Purpose:
# Make multiple links in current working directory. A "ln -s" wrapper.
# Usage:
# lns_multi_cwd.bash lnk_target_path_1 lnk_target_path_2 ...
# lns_multi_cwd.bash /path/dir/*
@photonxp
photonxp / sed_tagkey_in_dir.bash
Last active September 25, 2018 08:04
Tag line editing, tag key editing
#!/bin/bash
# Tag line editing
# Change the line
# from
# vocabulary grammar
# to
# tag:: vocabulary grammar
# Change by given tag value such as "vocabulary" or "grammar"
# Omit the tag line if they already have the key word of "tag"
@photonxp
photonxp / add_tags_by_excluding_existing_tags.sh
Last active September 25, 2018 08:12
Tag line editing. Exclude lines that have existing "tag:".
#!/bin/sh
# Purpose:
# Exclude lines that have existing "tag:"
# Find lines that contains target string "voc"
# Insert new tags "tag::" to the matched lines
# Use non-extended regex to improve compatibility
# Methods:
# Use the backslash syntax \1 \2 \1d \2d ..
@photonxp
photonxp / touchbash
Last active October 7, 2018 10:56
touch sh bash files with additional operations such as give file names and chmod them
#!/bin/sh
# Once the global warmth reaches a tipping point,
# the chain-reaction could be irreversible,
# so are we ready for the ticking bomb?
# Usage:
# ./touchsh file_name
# No touch operation if file already existed.
@photonxp
photonxp / sha1sum_file_vs_sumstr.sh
Last active September 11, 2018 11:53
compare generated-sha1sum of a given file to a sum_string
#!/bin/bash
# Usage:
# sha1sum_file_vs_sumstr.sh /path/to/file sum_str
sha1sum "$1"
sha1_result=$(sha1sum "$1")
sum=${sha1_result%% *}
echo
@photonxp
photonxp / notify_boot_in_profile.sh
Last active July 8, 2018 11:11
script to check if the boot partition has enough remaining space
#!/bin/bash
# call this file in your profile as background job
set -e
# Adjust this value if it's too long or too short to wait
sleep 600
# You need to change this path for your own directory
BASE_DIR=/path/to/your_notify_dir
@photonxp
photonxp / purge_kernel_by_rules.sh
Last active January 12, 2019 11:05
Purge redundant Ubuntu kernel files by rules defined in the script, such as the number of kernels to be preserved
#!/bin/bash
# What if we could adjust the clock,
# making a day of a virtual AI world much shorter than ours?
# What if a virtual AI being could spend its whole long life
# in a blink of our eyes?
#############################################################
# Purpose:
# Purge redundant Ubuntu kernel files by rules defined in the script
@photonxp
photonxp / cutmp3_usage.txt
Created April 2, 2018 05:32
Usage of cutmp3 on Ubuntu Linux
# http://manpages.ubuntu.com/manpages/trusty/man1/cutmp3.1.html
cutmp3 -i source_file.mp3 -a 0:37 -b 1:25
cutmp3 -i file.mp3 -a 0:37 -b 1:25 -o file_ -q
# cut from the start
cutmp3 -i file.mp3 -a 0:00 -b 1:25 -o file_ -q
@photonxp
photonxp / eog_latest_img.sh
Last active October 28, 2018 03:17
Use EOG to show the latest image file under a given directory dynamically
#!/bin/sh
# images are continueously updated in a given directory [img_src_dir]
# use the `ls -t` command to find the latest image file
# use eog to show the latest image file dynamically
# In the eog Preferences/Slideshow, uncheck the "Loop sequence" option
# So EOG and Entangle can be used together
img_src_dir="/home/to/Capture"
@photonxp
photonxp / replace_image_with_images_in_loop.sh
Last active January 28, 2018 09:02
copy images from a directory to replace a given test image one by one
#!/bin/sh
# https://superuser.com/questions/211561/loop-pictures-from-a-folder-and-display-fullscreen-slideshow
# It's better to adjust gthumb to "Fit to window" in preferences.
# Image Viewer(eog) could do the same job as gthumb, if in full screen mode.
# use absolute path instead of relative path in case something went wrong
test_img_path="/path/to/test.jpeg"
img_folder_path="/path/to/testdir_with_images"