This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum ArithmeticExpression { | |
case number(Int) | |
indirect case addition(ArithmeticExpression, ArithmeticExpression) | |
indirect case multiplication(ArithmeticExpression, ArithmeticExpression) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Result<Value> { | |
case Success(Value) | |
case Failure(NSData?, ErrorType) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println("hello world") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println("hello world") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c like struct | |
type TreeNode struct { | |
Value int | |
Left, Right *TreeNode // pointers | |
} | |
func DfsInOrder(treeNode *TreeNode) { | |
if treeNode == nil { | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct LinkNode { | |
Value int | |
Prev, Next *LinkNode | |
} |