Skip to content

Instantly share code, notes, and snippets.

View alextanhongpin's full-sized avatar

Alex Tan Hong Pin alextanhongpin

View GitHub Profile
Object.keys(obj).length === 0 && obj.constructor=== Object
/*
* 60 FPS Scroll
*
* prevent accidental click on links
* prevent other touch-related events
* 60fps scroll
*
* Usage:
* import Scroll from './scroll'
* Scroll()
export default class Dispatcher {
constructor() {
this._events = [];
this._service = [];
}
on(action, fn) {
if (!action) throw new Error('DispatcherError: Missing variable' + action + ' is not defined');
@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"
/*
```html
<img data-src="/path/to/image.jpg" alt="">
```
```css
img {
@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
}
package isogram
import (
"testing"
)
// booB #2nd order isogram
// Caucasus # 2nd order isogram
// geggee # 3rd order
package main
// Run the following command
// $ time go run main.go
// Golang Benchmark
// real 0m8.102s
// user 0m1.004s
// sys 0m0.504s
@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
@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})
}