Skip to content

Instantly share code, notes, and snippets.

@pec1985
pec1985 / ResizingImages.js
Created March 10, 2011 23:04
Resize images from the Image Gallery
// testend on iOS
/*
Copyright 2011 Pedro Enrique
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
@pec1985
pec1985 / PlayingWithDates.js
Created March 18, 2011 22:40
date in UTC and Current
function utcDate(e){
var day = e.getUTCDate();
var month = e.getUTCMonth()+1;
var year = e.getUTCFullYear();
var hour = e.getUTCHours();
var minutes = e.getUTCMinutes();
var seconds = e.getUTCSeconds();
if(month<10){month = '0'+month;}
if(day<10){day = '0'+day;}
if(hour<10){hour = '0'+hour;}
@pec1985
pec1985 / mySuperCoolRow.js
Created March 23, 2011 22:33
Center the title of a row with the Super Cool Row function
// Created by @pecdev with the help of @pec1985
// Follow either on Twitter
//
// Center the title of a row with the Super Cool Row function
var tableData = [];
function mySuperCoolRow(e){
var row = Ti.UI.createTableViewRow({backgroundColor:e.bgColor,height:e.height});
var label = Ti.UI.createLabel({text:e.title,width:'auto',height:50,font:{fontSize:20,fontWeight:'bold'}});
@pec1985
pec1985 / slide-to-unlock.js
Created March 23, 2011 22:35
Titanium Mobile code for slider control functionality
// Titanium Mobile code for slider control functionality
//----------------------------------------
// @CJ_Reed 23rd Dec 2010
var sliderView = Titanium.UI.createView({top:100,height:50,left: 40,width:240,backgroundColor:'#000'});
var sliderButton = Titanium.UI.createView({width:96,borderRadius:5,backgroundColor:'#bbb',height:sliderView.height,left:sliderView.left,top:sliderView.top});
Titanium.UI.currentWindow.add(sliderView);
Titanium.UI.currentWindow.add(sliderButton);
function unlock (){
@pec1985
pec1985 / TableViewIndex.js
Last active September 25, 2015 11:08
Get the right column of letters on a table view
/* Ever wondered how to get the nice column of letters in the right side
* of the table 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 / ColorClock.js
Created April 19, 2011 03:56
Change background color as time passes by
// inspired on http://www.joelpeterson.com/clock/
// and most of the code taken from there as well
var win = Ti.UI.createWindow({
orientationModes: [3, 4]
});
var clock_bg = Ti.UI.createView({
backgroundColor: '#444444',
top: 20,
left: 20,
@pec1985
pec1985 / fileToMD5.js
Created April 19, 2011 20:56
Get an external JSON file, write it the file system, and convert it to an MD5 hash
var win = Ti.UI.createWindow();
// here the reponse will be written
var texArea = Ti.UI.createTextArea({value:'',top:20,right:20,left:20,bottom:20,backgroundColor:'white', font:{fontSize:20}});
win.add(texArea);
win.open();
@pec1985
pec1985 / require.js
Created April 21, 2011 00:38
How to use require() with Titanium
// this would be app.js (for example)
var UI = require('myfile'); // no .js extension
var win = UI.Window({backgroundColor:'#999'});
var view = UI.View({top:20,left:20,right:20,bottom:20,backgroundColor:'#ccc'});
win.add(view);
win.open();
@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";';
var win = Titanium.UI.createWindow({
top:0,
backgroundColor:'#ccc'
});
var toolbar = Ti.UI.createToolbar({
top:0
});
var b1 = Ti.UI.createButton({