Skip to content

Instantly share code, notes, and snippets.

@omorandi
omorandi / app.js
Created December 19, 2010 10:41
Appcelerator Titanium Mobile - Custom events
var win1 = Titanium.UI.createWindow({
title:'Window 1',
backgroundColor:'#fff'
});
var label1 = Titanium.UI.createLabel({
color:'#999',
text:'Window 1\nClick anywhere for opening Window 2',
textAlign:'center',
@omorandi
omorandi / gist:1013226
Created June 7, 2011 21:31
Two methods for sending SMS messages with Titanium Mobile on Android throught native intents
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff',
layout: 'vertical'
});
var bt1 = Ti.UI.createButton({title: 'send message (method 1)', top: 200});
bt1.addEventListener('click', function(e)
@omorandi
omorandi / gist:1156232
Created August 19, 2011 07:01
Small javascript for decoding mashape's job posting @ http://www.mashape.com/jobs
var text = '576520776f756c64206c6f766520746f2073656520796f757220636f646520696e7374656164206f6620736f6d65207061706572732c20776520646f6e27742077616e74204954206d616e61676572732c2077652077616e74207265616c206861636b6572732e20576527726520666f6375736564206f6e206368616e67696e67207468652077617920736572766963657320616e6420646174612061726520646973747269627574656420616e6420636f6e73756d65642e20496620796f752077616e7420746f207075742074686520776f726c642075707369646520646f776e2c20616e6420796f7520647265616d732061726520636f64656420696e204a41564120616e64206261736564206f6e206d6f6e676f44422c2073686f757420697420686572653a206861636b657273406d6173686170652e636f6d20496620796f75277265206b69636b2d61737320646576656c6f706572207765276c6c2066696e6420796f752e204265206172726f67616e742e';
var decode = function(txt) {
var decoded = '';
for (var i = 0; i < txt.length; i += 2) {
var b = '' + txt.charAt(i) + txt.charAt(i+1);
var c = parseInt(b, 16);
decoded += String.fromCharCode(c);
}
var CustomSwitch = function(onText, offText, value) {
// the custom view
var view = Ti.UI.createView();
var label = Ti.UI.createLabel();
var sw = Ti.UI.createSwitch();
view.add(label);
view.add(sw);
@omorandi
omorandi / gist:1226220
Created September 19, 2011 09:37
Get asset files in Ti iOS modules
#define MODULE_ID @"your.module.id"
- (NSURL *)getAssetURL:(NSString*)resFile
{
NSString * filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"modules/%@/%@",MODULE_ID, resFile]];
return [NSURL fileURLWithPath:filePath];
}
+ (NSData*) resolveAppAsset:(NSString*)path;
{
NSString *ServerAddr = SERVER_ADDRESS;
NSString *ServerPort = SERVER_PORT;
NSString *path_url = [NSString stringWithFormat:@"http://%@:%@/%@",ServerAddr, ServerPort, path];
NSURL *url = [NSURL URLWithString:path_url];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
if ([request responseStatusCode] != 200)
ip_addr = "localhost"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(("gmail.com",80))
ip_addr = s.getsockname()[0]
except socket.error, msg:
s.close()
s = None
+ (NSData*) resolveAppAsset:(NSString*)path;
{
static NSMutableDictionary *map;
if (map==nil)
{
map = [[NSMutableDictionary alloc] init];
//here the entry for app.js is created
//(I filled the hex string with garbage - it's only an example)
[map setObject:dataWithHexString @"DEADBEEF…" forKey:@"app_js"];
}
@omorandi
omorandi / gist:1626791
Created January 17, 2012 14:23 — forked from jaraen/gist:1626498
Shadow property in TiUIView.m
-(void)setShadow_:(id)args
{
if(args != nil)
{
self.layer.masksToBounds = NO;
if ([args objectForKey:@"shadowOffset"] != nil) {
CGPoint p = [TiUtils pointValue: [args objectForKey:@"shadowOffset"]];
CGSize shadowOffset = {p.x,p.y};
@omorandi
omorandi / app.js
Created March 13, 2012 15:36
simple profiling test with Ti Mobile iOS
Ti.include('included.js');
function launch_test1() {
test1();
}