Skip to content

Instantly share code, notes, and snippets.

@yuan3y
yuan3y / git rebase amend with signature
Created February 4, 2022 06:01
one-liner command to sign all commits until master
git rebase --exec 'git commit --amend --no-edit -n -S' -i master
@yuan3y
yuan3y / unban.sh
Created April 11, 2021 08:55
unban an IP from denyhosts
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo -e "Error:\n\tProvide IP as the first param"
echo -e "Usage:\n\t$0 <IP>"
exit 1
fi
/etc/init.d/denyhosts stop
echo '
@yuan3y
yuan3y / only-owner-can-run.sh
Created February 28, 2021 01:09
How to ensure a script is run by the same user as the owner of a file
#!/usr/bin/env bash
script_runner=$(id -u -n)
file_owner=$(stat -c '%U' ./index.html)
[ $script_runner != $file_owner ] && { echo "please run script as $file_owner with 'sudo -u $file_owner $0'"; exit 1; }
echo "all good, do what you want $file_owner to do here"
@yuan3y
yuan3y / .inputrc
Created March 20, 2020 13:12
put it under ~, that is ~/.inputrc
## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward
@yuan3y
yuan3y / newMonth.sh
Created January 21, 2019 08:28
create folders for the current month under ~/Downloads/YYYY/MM and softlink personal to ~/Downloads/personal/YYYY/MM
#!/usr/bin/env bash -x
YYYYslashMM=$(date +%Y/%m)
cd ~/Downloads
mkdir -pv ./$YYYYslashMM
rm current
ln -s $YYYYslashMM/ current
mkdir -pv ./personal/$YYYYslashMM
cd ./$YYYYslashMM
rm personal
ln -s ../../personal/$YYYYslashMM/ personal
@yuan3y
yuan3y / .gitconfig
Created July 4, 2018 00:41
git alias config I'm comfortable with
[alias]
co = checkout
com = checkout master
fo = fetch origin
fom = fetch origin master
ci = commit
st = status
br = branch
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
@yuan3y
yuan3y / .bashrc
Created July 4, 2018 00:38
.bashrc used in Ubuntu
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@yuan3y
yuan3y / jekyll.service
Last active June 5, 2021 12:57
to make `jekyll serve` a system service and start on boot
# Author: @yuan3y
# Date: 2017-09-29
# Description: to make `jekyll serve` a system service and start on boot
#
# Usage: place this file at `/etc/systemd/system/jekyll.service`
# then run
# sudo systemctl start jekyll.service
# sudo systemctl enable jekyll.service
[Unit]
@yuan3y
yuan3y / singapore-blood-stock-level.js
Created May 12, 2017 07:14
find blood stock level in Singapore bloodbank https://www.redcross.sg/
/*jQuery way*/
Array.from([["last_update",jQuery('.last_update').text().slice(25)]].append(jQuery('div.human').map((a,b)=>{return [[jQuery(b).children('.blank_humam').text(), jQuery(b).children('.fill_humam').prop('style').height]];}))).reduce((p,c,i)=>{p[c[0]]=c[1]; return p;},{})
/*VanillaJS functional equivalence*/
Array.from([["last_update",document.querySelector('.last_update').innerText.slice(25)]].append(Array.from(document.querySelectorAll('div.human')).map((b)=>{return [b.children[0].innerText, b.children[1].style.height];}))).reduce((p,c,i)=>{p[c[0]]=c[1]; return p;},{})
@yuan3y
yuan3y / install_prevent_lock_screen_dim.sh
Last active March 7, 2018 21:27
This script prevents lock screen from dimming. Tested on Ubuntu 16.04.2 LTS with default Unity interface.
#!/bin/bash
# Copyright (c) 2017 @yuan3y
# Released under MIT License
# Tested on Ubuntu 16.04.2 LTS with default Unity interface
#
# USAGE:
# chmod +x install_prevent_lock_screen_dim.sh
# ./install_prevent_lock_screen_dim.sh
scriptFile=~/.prevent_lock_screen_dim.sh