Skip to content

Instantly share code, notes, and snippets.

@pec1985
pec1985 / app.js
Created September 26, 2011 23:07
Cache Remote Images
var Utils = {
RemoteImage: function(a){
a = a || {};
var md5;
var needsToSave = false;
var savedFile;
if(a.image){
md5 = Ti.Utils.md5HexDigest(a.image)+'.jpg';
savedFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,md5);
if(savedFile.exists()){
@pec1985
pec1985 / app.js
Created August 1, 2011 20:41
XHR function with callback
HTTPRequest({
ur:'http://example.com/somefile.json',
type:'GET',
success: function(a){
var json = JSON.parse(a);
// do something else
},
error: function(response, message){
// handle error
}
@pec1985
pec1985 / app.js
Last active July 20, 2022 16:33
Cross PLatform Nav Controller
var Navigation = require('navigation');
var rootWindow = Ti.UI.createWindow({
backgroundColor: 'green'
});
var btn = Ti.UI.createButton({
title: 'next'
});
@pec1985
pec1985 / webViewZoom.js
Created April 21, 2011 01:23
Increase zoom level in WebView
var win = Titanium.UI.createWindow({
backgroundColor:'#fff'
});
var webView = Ti.UI.createWebView({ url:'http://www.appcelerator.com', scalesPageToFit:true,setZoomScale:2, top:0, left:0});
win.add(webView);
var firstTime = true;
var htmlHack = '';
htmlHack += 'var element = document.createElement("meta");';
htmlHack += 'element.name = "viewport";';
@pec1985
pec1985 / app.js
Last active January 30, 2018 14:58
Array indexOf vs for loop
function Pe(){};
var len = 1000000;
var half = len / 2;
var array = [];
var last = new Pe();
while(len--) {
array.push(new Pe());
}
array.push(last);
@pec1985
pec1985 / app.js
Created August 31, 2012 18:27
How to create a simple memory leak with Titanium
var memLeakArray = [];
function FirstWindow() {
var win = Ti.UI.createWindow({
backgroundColor: '#ccc'
});
var btn = Ti.UI.createButton({
title: 'open next',
width: Ti.UI.SIZE,
@pec1985
pec1985 / listview_index_column.js
Last active December 28, 2015 01:28
Index column in the listview
/* Ever wondered how to get the nice column of letters in the right side
* of the list view?
*
* Here is an example:
* 1. We take a list of names from a json file
* 2. We need to sort them by either first name or last name
* 3. We need to create a row header once in a while, when the first letter changes
* 4. We need to create a table index
*
*/
@pec1985
pec1985 / RHelper.java
Created June 24, 2013 03:54
Helper to get R. in Titanium Android
package com.pec1985.tigolf;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.util.TiRHelper.ResourceNotFoundException;
public class RHelper {
public static int getString(String str){
try {
return TiRHelper.getApplicationResource("string."+str);
@pec1985
pec1985 / app.js
Created May 16, 2013 17:17
Simple script to create a lot of ACS Users with Titanium
var json = {"HasMore":false,"FuelStations":[{"StationId":"POIID-2011Q1_32035298","FuelPrice":[{"FuelType":1,"CapacityPrice":{"Value":4.139,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-10T12:17:00.000+0000","PriceTimestampGMT":"2013-05-10T19:17:34.000+0000"},{"FuelType":4,"CapacityPrice":{"Value":4.259,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-13T17:03:00.000+0000","PriceTimestampGMT":"2013-05-14T00:03:30.000+0000"},{"FuelType":3,"CapacityPrice":{"Value":4.159,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-13T17:03:00.000+0000","PriceTimestampGMT":"2013-05-14T00:03:30.000+0000"},{"FuelType":2,"CapacityPrice":{"Value":4.099,"Units":"GAL","Currency":"USD"},"PriceTimestampLocal":"2013-05-14T14:25:00.000+0000","PriceTimestampGMT":"2013-05-14T21:25:45.000+0000"}],"Brand":"76","LastUpdateTimestamp":"2013-05-16T04:06:26.000+0000","Routing":{"href":"http://fuel.si.public.devbln.europe.nokia.com/1.0/routing/calculateroute?waypoint=37.332332611083984,-122.0312194824
@pec1985
pec1985 / app.js
Created May 10, 2013 17:09
Double Slider
var Slider = require('slider');
var win = Ti.UI.createWindow();
var slider = Slider({
left: 10,
right: 10,
height: 40
});