Skip to content

Instantly share code, notes, and snippets.

View EJSohn's full-sized avatar

Harley Son EJSohn

View GitHub Profile
@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 / 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 / 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 / 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
public enum Result<Value> {
case Success(Value)
case Failure(NSData?, ErrorType)
}
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)
}
}
enum ArithmeticExpression {
case number(Int)
indirect case addition(ArithmeticExpression, ArithmeticExpression)
indirect case multiplication(ArithmeticExpression, ArithmeticExpression)
}
// declare variables.
var today = WeatherCondition.sunny(24)
var yesterday = WeatherCondition.cloudy(Cloud.cirrus, 10)
switch today {
case .sunny(let temperature):
print("today's temperature is \(temperature).")
case .rainy(let inchesPerHour):
print("\(inchesPerHour) inches of rainwater.")
enum Cloud {
case cirrus
case cumulus
case altocumulus
case cumulonimbus
}
enum WeatherCondition {
case sunny(temperature: Float)
case rainy(inchesPerHour: Float)
// Enumeration of type Fruit.
enum Fruit: Int {
case apple = 1000
case banana = 500
case grape = 2500
}
// declare variable.
let orderedFruit: Fruit = .apple