Skip to content

Instantly share code, notes, and snippets.

View luochen1990's full-sized avatar
🏠
Working from home

Luo Chen luochen1990

🏠
Working from home
View GitHub Profile
@luochen1990
luochen1990 / EitherExample.java
Created May 15, 2018 07:45
ADT Sum Type in Java
import java.util.function.Function;
public class EitherExample {
public static void main(String[] args) {
Either<String, Integer> x = new Left<>("hello");
Either<String, Integer> y = new Right<>(123);
System.out.println("hello");
System.out.println(x);
System.out.println(y);
}
@luochen1990
luochen1990 / conemu-msys2-bash-task.txt
Created June 19, 2018 12:21
Cmder (ConEmu) Task config: {msys2:bash}
Task parameters:
/icon "c:\dev\msys2\msys2.ico" /dir "%CMDER_START%"
Command:
set CHERE_INVOKING=1 & set MSYS2_PATH_TYPE=inherit & %ConEmuDrive%\dev\msys2\usr\bin\bash.exe --login -i -new_console:t:"bash"
References:
@luochen1990
luochen1990 / .bashrc
Last active August 2, 2018 23:53
the `dx` alias: a convenient wrapper of the `docker exec` command
docker_exec() {
matches=$( docker ps | grep $1 )
echo "$matches"
pid=$(echo $matches | awk "{print \$1}" )
echo Entering: $pid
docker exec -it $pid sh
}
alias dx="docker_exec"
@luochen1990
luochen1990 / mklink_examples.md
Last active February 12, 2019 08:18
Create symbolic link in Windows
@luochen1990
luochen1990 / SimpleABAC.hs
Last active January 9, 2019 07:22
a simple ABAC (Attribute Based Access Control) system implementation in Haskell
-- | This is a module to explain the Attribute based access control system
-- , [ABAC](https://en.wikipedia.org/wiki/Attribute-based_access_control)
-- , [XACML](https://en.wikipedia.org/wiki/XACML)
module SimpleABAC where
import Data.Foldable
type AccessorAttr = String
type ResourceAttr = String
type OperationAttr = String
@luochen1990
luochen1990 / .zshrc
Last active May 23, 2019 06:41 — forked from zedongh/.zshrc
zsh config
[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'
[[ -e ~/.shrc ]] && emulate sh -c 'source ~/.shrc'
source $HOME/.antigen.zsh
# POWERLEVEL9K_INSTALLATION_PATH=$ANTIGEN_BUNDLES/bhilburn/powerlevel9k
antigen use oh-my-zsh
antigen bundles <<EOF
npm
@luochen1990
luochen1990 / ddns.md
Last active February 10, 2022 09:48
DDNS (via DNSPOD API)

GET WAN IP Address

> nslookup myip.opendns.com. resolver1.opendns.com

...
Name: myip.opendns.com
Address: 101.69.24.2
@luochen1990
luochen1990 / haskell-base-partial-functions.md
Last active August 7, 2019 09:40
partial function list of the base package

Data.Foldable

  • foldr1
  • foldl1
  • maximum
  • minimum
  • maximumBy
  • minimumBy

Data.List

  • head
@luochen1990
luochen1990 / call-stack-cut-off.hs
Created June 16, 2019 09:00
A demonstration about how an improper call to an untraceable partial function cut off the call stack
import GHC.Stack
-- | a wrapper function to make "last" from base traceable
last' :: HasCallStack => [a] -> a
last' xs = case xs of [] -> error "abuse last"; _ -> last xs
-- | a untraceable partial function
foo :: [Int] -> Int
foo xs = last' xs + 1
@luochen1990
luochen1990 / the-concept-of-totality.md
Last active June 16, 2019 11:25
The Concept of Totality, with Haskell examples

The Concept of Totality

See the definition of partial function in wikipedia

Total Function & Partial Function

examples of total functions: