Skip to content

Instantly share code, notes, and snippets.

View alextanhongpin's full-sized avatar
😹
Focusing

Alex Tan Hong Pin alextanhongpin

😹
Focusing
View GitHub Profile
@alextanhongpin
alextanhongpin / sum-square-difference.go
Created March 21, 2017 07:00
Project Euler #6: Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
package main
// Answer: 25164150
// Find the difference between the sum of the squares
// of the first one hundred natural numbers and the square of the sum.
import (
"fmt"
"math"
)
@alextanhongpin
alextanhongpin / 06-sum-square-difference.v2.go
Created March 21, 2017 07:20
Project Euler #06 - Similar solution, but written with function that returns a channel
package main
// Answer: 25164150
// Find the difference between the sum of the squares
// of the first one hundred natural numbers and the square of the sum.
// Function that returns a channel
// real 0m0.284s
// user 0m0.151s
// sys 0m0.066s
@alextanhongpin
alextanhongpin / 06-sum-square-difference.v3.go
Created March 21, 2017 07:24
Project Euler #06 - Alternative solution
package main
// Answer: 25164150
// Find the difference between the sum of the squares
// of the first one hundred natural numbers and the square of the sum.
import (
"fmt"
"math"
)
@alextanhongpin
alextanhongpin / 01-mutex.go
Created March 30, 2017 11:09
sample-mutex
package main
import (
"fmt"
"sync"
)
func main() {
wg := &sync.WaitGroup{}
wg.Add(100)
@alextanhongpin
alextanhongpin / 02-mutex.go
Created March 30, 2017 11:09
Sample mutex 2
package main
import (
"fmt"
"sync"
)
func main() {
m := &sync.Mutex{}
wg := &sync.WaitGroup{}
@alextanhongpin
alextanhongpin / blocking.go
Created March 30, 2017 11:16
Blocking example using golang channels
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan bool)
start := time.Now()
@alextanhongpin
alextanhongpin / parallel.go
Created April 4, 2017 06:40
Running multiple processes with golang routines
package main
import (
"fmt"
)
func email() {
}
func slack() {
@alextanhongpin
alextanhongpin / postgres.go
Created April 4, 2017 16:35
Working example for postgres with golang
package main
import (
"fmt"
"time"
"github.com/lib/pq"
)
func getBook(bookID int) (Book, error) {
@alextanhongpin
alextanhongpin / README.md
Last active August 20, 2017 16:41
Shell script to setup Scala project

Getting started

How to create a sbt project.

  1. Prepare the setup.sh file
  2. Make an executable out of it: chmod +ux setup.sh
  3. Run the setup ./setup.sh

To run the web server

@alextanhongpin
alextanhongpin / play4scala.sh
Created April 16, 2017 18:28
Create new scala play application
sbt new playframework/play-scala-seed.g8