Skip to content

Instantly share code, notes, and snippets.

View tanhauhau's full-sized avatar

Tan Li Hau tanhauhau

View GitHub Profile
@tanhauhau
tanhauhau / CursorLooper
Created June 27, 2015 02:06
Looping Android Cursor. Saving the time to write the loop each time and close the cursor
public class CursorLooper<K>{
public interface Extract<K>{
public K extract(Cursor cursor);
}
private Extract<K> extract;
public CursorLooper(Extract<K> extract) {
this.extract = extract;
}
@tanhauhau
tanhauhau / AlarmReceiver.java
Created August 20, 2015 04:24
Wakeful Scheduled Service
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
/**
* Created by lhtan on 20/8/15.
* Refer from: https://randling.wordpress.com/2013/12/29/wakeful-and-repeatable-background-service-on-android/#comment-690
*/
@tanhauhau
tanhauhau / ColorUtil.java
Created August 24, 2015 14:55
White or black text based on background colour
import android.graphics.Color;
/**
* Created by lhtan on 24/8/15.
* Based on How to decide font color in white or black depending on background color?
* http://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color
*/
public class ColorUtil {
/**
* compute text color, either white or black based on colorString
@tanhauhau
tanhauhau / ColorUtil.java
Created August 24, 2015 14:55
White or black text based on background colour
import android.graphics.Color;
/**
* Created by lhtan on 24/8/15.
* Based on How to decide font color in white or black depending on background color?
* http://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color
*/
public class ColorUtil {
/**
* compute text color, either white or black based on colorString
@tanhauhau
tanhauhau / decreaseITunesVolume.scpt
Created September 13, 2015 09:07
Adjust iTunes volume through Applescript
tell application "iTunes"
set vol to sound volume
set vol to vol - 10
if vol is less than 0 then
set vol to 0
end if
set the sound volume to vol
end tell
@tanhauhau
tanhauhau / ionicLazyLoadCache.js
Created December 12, 2015 13:22
ionic-image-lazy-load + imgCache
Combination of
1. ionic-image-lazy-load (https://github.com/paveisistemas/ionic-image-lazy-load)
2. imgCache (https://github.com/chrisben/imgcache.js/)
Usage:
<image-lazy-cached image-lazy-src="{{image}}" image-lazy-loader="dots"></image-lazy-cached>
Installation:
1. Cordova File and Cordova File Transfer plugin
language: node_js
node_js:
- 4.2
before_script:
- npm install -g bower
- bower install
@tanhauhau
tanhauhau / .travis.yml
Last active April 13, 2016 13:45
Node.js Travis CI
language: node_js
node_js:
- 4.2
@tanhauhau
tanhauhau / lazy.sh
Created April 13, 2016 13:46
Lazy node.js .travis.yml
curl https://gist.githubusercontent.com/tanhauhau/405e39884e80288615a7b51181fd5228/raw/9045c2e219547f0a228da630abff345d8add0c47/.travis.yml > .travis.yml
curl https://gist.githubusercontent.com/tanhauhau/71998bf221810186f046db94cda10c4e/raw/d1e8aee0981a96c20f94de6db386da048face423/.travis.yml > .travis.yml