Skip to content

Instantly share code, notes, and snippets.

View oldratlee's full-sized avatar
🐥
Hello world!

李鼎 oldratlee

🐥
Hello world!
View GitHub Profile
@oldratlee
oldratlee / error-trap.sh
Last active October 25, 2024 02:28
error trap in bash
#!/bin/bash
set -eEuo pipefail
# https://stackoverflow.com/questions/6928946/mysterious-lineno-in-bash-trap-err
# https://stackoverflow.com/questions/64786/error-handling-in-bash
# https://stackoverflow.com/questions/24398691/how-to-get-the-real-line-number-of-a-failing-bash-command
# https://unix.stackexchange.com/questions/39623/trap-err-and-echoing-the-error-line
# https://unix.stackexchange.com/questions/462156/how-do-i-find-the-line-number-in-bash-when-an-error-occured
# https://unix.stackexchange.com/questions/365113/how-to-avoid-error-message-during-the-execution-of-a-bash-script
# https://shapeshed.com/unix-exit-codes/#how-to-suppress-exit-statuses
@oldratlee
oldratlee / comment-coverage-report.sh
Last active December 7, 2018 13:31
Generate comment coverage report for java of maven project, markdown table format
#!/bin/bash
# comment-coverage-report.sh
# generate comment coverage report, markdown table format
#
# NOTE:
# 1. run at project root dir
# 2. install ohcount: https://github.com/blackducksw/ohcount
# if you use mac install by brew: brew install ohcount
set -euo pipefail
@oldratlee
oldratlee / log-config.md
Last active October 15, 2018 11:37
log dependencies config
@oldratlee
oldratlee / gcor.sh
Last active July 24, 2017 05:42
checkout most recent modified branch
gcor() {
# http://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
# --sort=-committerdate : sort branch by commit date in descending order
# --sort=committerdate : sort branch by commit date in ascending order
git branch -a --sort=committerdate "$@" |
awk -F'remotes/origin/' '/remotes\/origin\//{print $2}' |
tail -1 |
xargs git checkout
}
@oldratlee
oldratlee / ScalaLinearization.scala
Last active March 16, 2017 17:16
ScalaLinearization demo implementation by scala, based on https://gist.github.com/zavakid/05e18507ec3a311edcc87a4013b7d057
import scala.collection.immutable.ListSet
object ScalaLinearization {
case class Clazz(className: Symbol, superClasses: ListSet[Clazz])
// Ignore Any, AnyRef. Simplify demo implementation
val animal = Clazz('Animal, ListSet())
val furry = Clazz('Furry, ListSet(animal))
val hasLegs = Clazz('HasLegs, ListSet(animal))
@oldratlee
oldratlee / Linearization.java
Created January 6, 2017 13:07
Scala linearization demo implementation
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Linearization {
private static void linearization(String clazz, List<String> result, Map<String, List<String>> class2Supers) {
final List<String> supers = class2Supers.get(clazz);
@oldratlee
oldratlee / erlang-alias-functions-for-shell.sh
Last active September 27, 2016 18:26
shell convenient alias/function for #erlang
# Run erlang MFA(Module-Function-Args) conveniently, like
# erun fac1 main 25 # example from book programming erlang.
erun() {
if [ $# -lt 2 ]; then
echo "Error: at least 2 args!"
return 1
fi
erl -s "$@" -s init stop -noshell
}
set nocompatible
" set backspace=indent,eol,start
syntax on
set ignorecase
set hlsearch
set number
set relativenumber
@oldratlee
oldratlee / ghc.sh
Created July 22, 2016 23:46
Git/Http Converter
ghc() {
local url="${1:-$(git remote get-url origin)}"
if [ -z "$url" ]; then
echo "No arguement and Not a git repository!"
return 1
fi
if [[ "$url" =~ '^http' ]]; then
echo "$url" | sed 's#^https?://#git@#; s#$#\.git#; s#(\.com|\.org)/#\1:#' -r | c
else
<profile>
<id>java8+</id>
<activation>
<jdk>[1.6,1.7]</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>