Skip to content

Instantly share code, notes, and snippets.

View ricardoalcocer's full-sized avatar
💭
making music at https://alcomusic.com

Alco ricardoalcocer

💭
making music at https://alcomusic.com
View GitHub Profile
@ricardoalcocer
ricardoalcocer / getparameterbyname.js
Created January 4, 2013 19:16
Receives a full URL and a query string parameter and returns its value. Modified from (http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values) to work with Appcelerator Titanium. Example: var idValue=getParameterByName('http://somewebsite.com/page.php?id=12345','id'); idValue holds 12345
function getParameterByName(target,name){
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var results=target.match(regexS);
if(results == null){
return "";
}else{
return Ti.Network.decodeURIComponent(results[1].replace(/\+/g, " "));
}
@ricardoalcocer
ricardoalcocer / blimp_test.js
Last active December 11, 2015 05:29
Usage of the Blimp Client Library for Titanium
//
var apiAccessData={
user_name:'your_user_name_here',
api_key:'your_api_key_here',
base_url:'https://app.getblimp.com/api/v2',
app_id:'815e71539d113d681e3a365b96ddd1984ca8955a'
}
//
//
@ricardoalcocer
ricardoalcocer / gist:5041104
Last active December 14, 2015 06:18
Get row Id on Android when the row has child objects
function onMenuClick(e){
if(e.source.id!=='row'){ // row is user-defined
var selectedRowId=e.source.parent.rowId; // rowId is user-defined
}else{
var selectedRowId=e.row.rowId;
}
alert(selectedRowId)
}
// what will happen after the request? define your callbacks here!
var onSuccessCallback = function (e) {
// you'll receive:
//e.data
//e.status
//e.code
//
Ti.API.info(e.data);
}
@ricardoalcocer
ricardoalcocer / simulatehome.js
Created March 14, 2013 22:52
Simulate Android HOME BUTTON click on Appcelerator Titanium : Sends your app to background
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_MAIN
});
intent.addCategory(Ti.Android.CATEGORY_HOME);
Ti.Android.currentActivity.startActivity(intent);
@ricardoalcocer
ricardoalcocer / longpress.js
Created March 17, 2013 18:55
Simulate long press on Appcelerator Titanium for Android
var touched = false;
tableview.addEventListener('click', function(e)
{
touched = false;
});
tableview.addEventListener('touchstart', function(e){
touched = true;
setTimeout(function(){
if (touched)
alert("Long press");
@ricardoalcocer
ricardoalcocer / ontiapp.xml
Last active December 15, 2015 01:49
Appcelerator Titanium Android HOLO theme ICS
<android xmlns:android="http://schemas.android.com/apk/res/android">
<tool-api-level>14</tool-api-level>
<manifest>
<application android:theme="@android:style/Theme.Holo"></application>
</manifest>
</android>
@ricardoalcocer
ricardoalcocer / jsonparsing.js
Last active December 15, 2015 02:49
Titanium basic parsing JSON
var onSuccessCallback = function (e) {
var response=JSON.parse(e.data); // the magic happens with here
response.forEach(function(value, index, arr){
var tweet=value.text;
var created=value.created_at;
var source=value.source;
var user=value.user.screen_name;
var out=tweet + '\n' + 'Date: ' + created + '\n' + 'From: ' + source + '\n' + 'By: ' + user + '\n\n';
@ricardoalcocer
ricardoalcocer / xhr post.js
Last active December 15, 2015 02:49
xhr lib http post
var onSuccessCallback2=function(e){
Ti.API.info(e);
}
var url='http://www.posttestserver.com/post.php';
// this is the data you'll send to the web service
var payload={
property1:'value1',
property2:'value2'
@ricardoalcocer
ricardoalcocer / index.js
Last active January 19, 2017 10:48
Appcelerator: Basic XHR Twitter Alloy Example
var onSuccessCallback = function (e) {
var response=JSON.parse(e.data); // the magic happens with here
var tweetdata=[];
response.forEach(function(value, index, arr){
var payload={
tweet:value.text,
by:value.user.screen_name,
when:value.created_at,
source:value.source