Skip to content

Instantly share code, notes, and snippets.

@mauropm
mauropm / app.js
Created July 4, 2013 00:22
An example of generic app with different actions according to the button. It's showing how to manage the destruction of the window after you use it, and other nice things. To use: Create a new classic mobile project in Titanium Studio, and copy all this files to Resources directory. This is intended to work with Titanium Mobile SDK 3.1.1.GA, wit…
// INcluding memory management utils.
Ti.include('utils.js');
// root window.
var win = Ti.UI.createWindow({
backgroundColor:'white',
exitOnclose:true,
});
@mauropm
mauropm / app.js
Created April 26, 2013 19:41
Example of read/write files of any size using Streams in Titanium. In this example, we go from text to text, passing thru base64 encoding/decoding.
var win = Ti.UI.createWindow({
backgroundColor:'white',
});
var infile = Titanium.Filesystem.getFile('quixotebig.txt');
var instream = infile.open(Titanium.Filesystem.MODE_READ);
var outfile =
Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'quixote_base64.txt');
var outstream = outfile.open(Titanium.Filesystem.MODE_WRITE);
/**
* We're going to create an infinite scrollable list. In this case, we're going to show a date. When you swipe left,
* you'll see yesterday. Then the day before yesterday, and so on. Swiping right shows you tomorrow, and so on.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var isAndroid = Ti.Platform.osname === 'android';
/**
* Track where we are in the infinite scrollable views, and define how large of a step goes between each view.
*/
var currentDate = new Date(), msIntervalBetweenViews = 1000/*ms*/ * 60/*s*/ * 60/*m*/ * 24/*h*/;
@mauropm
mauropm / app.js
Created March 22, 2013 22:39
Example about how to handle window closing in Android, doing: Cleaning of the window's contents, remove all listeners and proper closing and null of the window.
Ti.include('utils.js');
// Base window
var win = Ti.UI.createWindow();
// Base launch button
var button = Ti.UI.createButton({
title:'Press here',
top: 10,
left: 10,
@mauropm
mauropm / methods.rb
Created March 8, 2013 22:06
how to create dynamically some code
class Dave
def start
puts 'Adentro de start'
def stop
puts 'Adentro de stop'
end
end
end
@mauropm
mauropm / n_times.rb
Created March 8, 2013 21:28
Nice example about lambda usage in ruby #metaprogramming
def n_times(n)
#codigo
lambda {|val| n * val}
end
two_times = n_times(2)
puts two_times.call(3)
#from Norberto's class
@mauropm
mauropm / app.js
Created February 15, 2013 01:08
Updates the tab's icon when changing from one tab to the other. To test this, create a new mobile project in Ti Appcelerator, then paste this gist's content into app.js. Run it in iOS.
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
@mauropm
mauropm / app.js
Created December 17, 2012 22:18 — forked from minhnc/app.js
var win = Ti.UI.createWindow();
win.open();
/// <<< Register & UnRegister Event Listeners
/**
* params: {event: 'event', callback: eventCallback}
*/
function registerEventListener(obj, params) {
if ( typeof obj._eventListeners == 'undefined' ) {
@mauropm
mauropm / paypal.html
Created October 22, 2012 07:47
paypal.html
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1.0, maximum-scale=1.0" >
<STYLE type="text/css">
BODY { background: url("http://groundctrl.s3.amazonaws.com/clients/avril/media/02/03/large.g95884km8h2e.jpeg") }
</STYLE>
<title>Hola hola</title>
</head>
<body background:url("http://groundctrl.s3.amazonaws.com/clients/avril/media/02/03/large.g95884km8h2e.jpeg")>
<center>
@mauropm
mauropm / app.js
Created August 15, 2012 15:56
Complex dialog in android with a view
var table = Titanium.UI.createTableView();
var row = Titanium.UI.createTableViewRow();
var view = Titanium.UI.createView({backgroundColor:'red',width:20,height:20});
row.height = 'auto';
row.add(view);
table.setData(row);
var dialog = Titanium.UI.createOptionDialog({
title: 'Hello',