Skip to content

Instantly share code, notes, and snippets.

## == SYSTEM
## required: Android SDK Build-tools 23.0.1
export ANDROID_HOME='TODO'
## export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
## export JAVA_HOME=$(/usr/libexec/java_home)
{
"Quang log": {
"prefix": "ql",
"body": [
"Ti.API.error('Quang: $1 ' + JSON.stringify( ${2:1} ));$3"
]
},
"WinManager load": {
@ptquang86
ptquang86 / titanium.pulltorefresh
Last active August 29, 2015 14:11
pull to refresh for Listview
var feedsController,
refreshControl,
loadMoreDisabled;
loadFeeds();
function loadFeeds() {
// this is a ListView
feedsController = Alloy.createController('feeds', {});
@ptquang86
ptquang86 / append.script.js
Last active August 29, 2015 14:02
Append JS/CSS dynamic
var head = document.getElementsByTagName( 'head' )[0];
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'css/templates/' + template + '.css';
head.appendChild(link);
var sources = [ 'js/jsrender.min.jsss', 'js/templates/' + template + '.jsss' ];
for(var i=0,ii=sources.length; i<ii; i++){
var script = document.createElement( 'script' );
// vendor
var express = require('express');
var app = express();
// depending on the placement, we can either catch or override routes
app.use(app.router);
// every route in the routes/user.js file will be served under /user
app.use('/user', require('./routes/user').middleware);

Working with Dates, Times, and Timezones

Top 10 recommendations for developers

Update: tzTime (documentation) is now available seperately from Lumenize. The examples below still work because tzTime is a dependency of Lumenize and included in that package (as well as Rally's App SDK v2.0p6 or greater). However, Lumenize includes a lot more functionality around time-series and temporal model aggregations, OLAP Cube, etc. If you just want the Time object, just grab tzTime.

What's the correct query clause to get all the transactions from March? The naive answer is "2012-03-01" &lt;= eventTimestamp &lt;= "2012-03-31" but what if the person worked in the eastern US and wanted timezone taken into account? Then the correct answer is "2012-03-01T05" &lt;= eventTimestamp &lt; "2012-04-01T04". Notice how the timeshift for the begging of March is different from the end. Getting this right is mind bendingly diff

@ptquang86
ptquang86 / js-cache-function-result.js
Created November 18, 2012 09:01
Javascript - Cache function result
// http://www.sitekickr.com/blog/?p=946&preview=true
function Cache() {
// create the cache object as a singleton (only one instance allowed)
if(typeof Cache.instance === 'undefined') {
Cache.instance = this;
}
var data = [ ]
@ptquang86
ptquang86 / ti.geo.js
Last active April 8, 2016 18:40
Titanium - Geolocation
exports.init = function() {
Ti.Geolocation.purpose = 'Mileage Calculate';
checkGeoPermission();
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
//
// SET ACCURACY - THE FOLLOWING VALUES ARE SUPPORTED
//
@ptquang86
ptquang86 / format.date.js
Created June 8, 2012 06:11
JavaScript Date Format
//http://blog.stevenlevithan.com/archives/date-time-format
//http://stevenlevithan.com/assets/misc/date.format.js
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
@ptquang86
ptquang86 / titanium.module.js
Created May 28, 2012 07:34
CommonJS modules
function Car() {
this.init.apply(this, arguments);
}
Car.prototype.init = function (make, model) {
this.make = make;
this.model = model;
};
Car.prototype.make = null;