Skip to content

Instantly share code, notes, and snippets.

@yuan3y
yuan3y / Countries.csv
Last active February 3, 2017 10:52 — forked from lenguyenthedat/Countries.csv
Country - Continent codes and names
continent_code country_code continent_name country_name country_iso3 country_number country_full_name
AS AF Asia Afghanistan AFG 004 Islamic Republic of Afghanistan
EU AX Europe Åland Islands ALA 248 Åland Islands
EU AL Europe Albania ALB 008 Republic of Albania
AF DZ Africa Algeria DZA 012 People's Democratic Republic of Algeria
OC AS Oceania American Samoa ASM 016 American Samoa
EU AD Europe Andorra AND 020 Principality of Andorra
AF AO Africa Angola AGO 024 Republic of Angola
NA AI North America Anguilla AIA 660 Anguilla
AN AQ Antarctica Antarctica ATA 010 Antarctica the territory South of 60 deg S
@yuan3y
yuan3y / git-line-add-delete-per-day.sh
Created April 14, 2017 09:48
Get number of lines added and deleted per day from your git repo
#!/bin/bash
ds() {
date --date="$1 days ago" +%Y-%m-%d
}
BRANCH=master # your branch here
echo "Date,LinesAdded,LinesDeleted"
for day in $(seq 1 10)
@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
@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 / jekyll.service
Last active September 8, 2024 13:48
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 / .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 / .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 / 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 / .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 / 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"