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 / 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 / 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 / base64ToImg.js
Created March 17, 2017 11:15
converts base 64 url to image
export default function dataURItoBlob (base64) {
const byteString = window.atob(base64)
const mimestring = 'image/jpeg'
const content = []
for (let i = 0; i < byteString.length; i++) {
content[i] = byteString.charCodeAt(i)
}
return new window.Blob([new Uint8Array(content)], {type: mimestring})
}
@alextanhongpin
alextanhongpin / benchmark_isogram_optimized.go
Created March 9, 2017 10:27
optimized version of isogram for golang
package main
// Run the following command
// $ time go run main.go
// Golang Benchmark
// real 0m8.102s
// user 0m1.004s
// sys 0m0.504s
package main
// Run the following command
// $ time go run main.go
// Golang Benchmark
// real 0m8.102s
// user 0m1.004s
// sys 0m0.504s
package isogram
import (
"testing"
)
// booB #2nd order isogram
// Caucasus # 2nd order isogram
// geggee # 3rd order
@alextanhongpin
alextanhongpin / isogram.go
Last active March 9, 2017 09:21
Test for isogram
package isogram
import (
"strings"
)
func IsIsogram(s string) bool {
if s == "" {
return false
}
/*
```html
<img data-src="/path/to/image.jpg" alt="">
```
```css
img {
@alextanhongpin
alextanhongpin / main.go
Created February 14, 2017 14:52 — forked from nmerouze/main.go
JSON-API with Go and MongoDB: Final Part
package main
import (
"encoding/json"
"log"
"net/http"
"reflect"
"time"
"github.com/gorilla/context"
export default class Dispatcher {
constructor() {
this._events = [];
this._service = [];
}
on(action, fn) {
if (!action) throw new Error('DispatcherError: Missing variable' + action + ' is not defined');