Skip to content

Instantly share code, notes, and snippets.

View EJSohn's full-sized avatar

Harley Son EJSohn

View GitHub Profile
enum ArithmeticExpression {
case number(Int)
indirect case addition(ArithmeticExpression, ArithmeticExpression)
indirect case multiplication(ArithmeticExpression, ArithmeticExpression)
}
func evaluate(_ expression: ArithmeticExpression) -> Int {
switch expression {
case let .number(value):
return value
case let .addition(left, right):
return evaluate(left) + evaluate(right)
case let .multiplication(left, right):
return evaluate(left) * evaluate(right)
}
}
public enum Result<Value> {
case Success(Value)
case Failure(NSData?, ErrorType)
}
@EJSohn
EJSohn / install_pyenv_virtualenv.sh
Last active October 10, 2018 15:06
bash script install pyenv&virtualenv in ubuntu.
# install ubuntu packages
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev
touch ~/.bash_profile
# install pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
@EJSohn
EJSohn / adduser.sh
Created October 10, 2018 12:25
bash script that add user in ubuntu
echo "Need root permission."
sudo echo "Done."
read -p "1. Enter username: " username
read -p "2. Enter comment: " comment
sudo adduser $username -c "$comment" --firstuid 10000 --ingroup developers --disabled-password --gecos ""
echo "User created!"
echo -e "$username\n$username" | sudo passwd $username >/dev/null 2>&1
sudo passwd -e $username >/dev/null 2>&1
echo "username : $username"
echo "initial password : $username"
@EJSohn
EJSohn / 1.go
Created April 19, 2019 15:36
translation code snippet (2019.04.20)
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
@EJSohn
EJSohn / hello_world.go
Created April 19, 2019 15:37
translation code snippet (2019.04.20)
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
@EJSohn
EJSohn / two_sum.go
Created April 19, 2019 15:39
translation code snippet (2019.04.20)
func twoSum(nums []int, target int) []int {
// map from int -> int
m := make(map[int]int)
// python like enumerate
for i, num := range(nums) {
// get value and check existence in map
// and in if statement where ok is the boolean comparison value
if index, ok := m[target - num]; ok {
// construct array and return values
// c like struct
type TreeNode struct {
Value int
Left, Right *TreeNode // pointers
}
func DfsInOrder(treeNode *TreeNode) {
if treeNode == nil {
return
struct LinkNode {
Value int
Prev, Next *LinkNode
}