Skip to content

Instantly share code, notes, and snippets.

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

Weerasak Chongnguluam iporsut

🏠
Working from home
View GitHub Profile
@iporsut
iporsut / gist:91039c160abd863f5be6
Created May 4, 2015 09:52
Account Deposit Method
func (acc *Account) Deposit(amount float64) {
acc.Balance += amount
}
@iporsut
iporsut / gist:2a6fad40c682f11d4e85
Created May 4, 2015 09:53
Account use Deposit Method
func main() {
acc := Account{Name: "Weerasak", Balance : 1000.00 }
acc.Deposit(500.00)
fmt.Println(acc)
}
type IO interface {
Read() string
Write(string)
}
@iporsut
iporsut / mylist.erl
Created May 10, 2015 13:20
mylist flatten
-module(mylist).
-export([flatten/1]).
flatten(L) -> flatten(L, []).
flatten([], Acc) -> Acc;
flatten([H|T], Acc) when is_list(H) -> flatten(T, Acc ++ flatten(H));
flatten([H|T], Acc) -> flatten(T, Acc ++ [H]).
@iporsut
iporsut / replace.hs
Created May 11, 2015 02:18
replace character in string
replace xs a b = replace' [] xs
where
replace' acc [] = acc
replace' acc (x:xs) | x == a = replace' (acc ++ [b]) xs
| otherwise = replace' (acc ++ [x]) xs
@iporsut
iporsut / main.go
Created May 11, 2015 22:40
scan line
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
)
rotate xs n | n >= 0 = drop n xs ++ take n xs
| otherwise = drop (length xs + n) xs ++ take (length xs + n) xs
@iporsut
iporsut / rotate.hs
Last active August 29, 2015 14:21
rotate cycle
rotate xs n | n >= 0 = zipWith (\_ x -> x) xs $ drop n $ cycle xs
| otherwise = take len $ drop dropLen $ (cycle xs)
where
len = length xs
dropLen = (len + (n `mod` (-len)))
@iporsut
iporsut / AlienLanguage.hs
Created May 16, 2015 11:54
Alien Language Haskell
import Control.Monad (replicateM)
parseTokens:: String -> [String]
parseTokens tokenStr = parseTokens' [] "" False tokenStr
where
parseTokens' acc word isGroup "" = acc
parseTokens' acc word isGroup (x:xs)
| not isGroup && x == '(' = parseTokens' acc "" True xs
| not isGroup && x /= '(' = parseTokens' (acc++[[x]]) "" False xs
@iporsut
iporsut / alienlanguage.go
Created May 16, 2015 12:02
Alien Language Go
package main
import (
"bytes"
"fmt"
"strings"
)
func main() {
// Read first line