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 / compress.js
Last active October 9, 2021 16:45
Sample usage for compress.js library.
const compress = new Compress()
const upload = document.getElementById('upload')
upload.addEventListener('change', (evt) => {
const files = [...evt.target.files]
compress.compress(files, {
size: 4, // the max size in MB, defaults to 2MB
quality: 0.75, // the quality of the image, max is 1,
maxWidth: 1920, // the max width of the output image, defaults to 1920px
@alextanhongpin
alextanhongpin / install_ip_macos.sh
Created May 22, 2017 16:35
Installation guide for ip command for mac
brew tap brona/iproute2mac
brew install iproute2mac
@alextanhongpin
alextanhongpin / play4scala.sh
Created April 16, 2017 18:28
Create new scala play application
sbt new playframework/play-scala-seed.g8
@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 / 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 / parallel.go
Created April 4, 2017 06:40
Running multiple processes with golang routines
package main
import (
"fmt"
)
func email() {
}
func slack() {
@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 / 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 / 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 / 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"
)