Skip to content

Instantly share code, notes, and snippets.

View flopezluis's full-sized avatar

Félix López flopezluis

  • Salamanca - Spain
View GitHub Profile
// 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
//
@flopezluis
flopezluis / app.js
Created February 2, 2011 08:46
Create 2 tabs
var isAndroid = Ti.Platform.osname == 'android';
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
var indicator = Titanium.UI.createActivityIndicator({
bottom:10,
height:50,
width:10,
message:"Cargando..."
});
@flopezluis
flopezluis / tic_tac_toe
Created April 13, 2011 17:07
Just for fun
players = ('0','X')
turn = 0
exit = False
board = {0:'-', 1:'-',2:'-', 3:'-', 4:'-',5:'-',6:'-', 7:'-',8:'-'}
win_combinatios= [[0,1,2], \
[3,4,5], \
[6,7,8], \
[0,3,6], \
[1,4,7], \
[2,5,8], \
@flopezluis
flopezluis / EventQueuerwhilerequestingdata.js
Created May 10, 2011 09:38
Event Queuer while requesting data. When you have taks that cannot be done between the ajax request
var function_after_ajax = [];
function fetchData() {
$.ajax({
url: url,
method: 'GET/POST',
dataType: 'json',
data:params,
success: onDataReceived
});
function onDataReceived() {
@flopezluis
flopezluis / ordered_hm.js
Created June 3, 2011 07:22
Ordered Hash Map
/*
* Simple hash map using javascript objects and an ordered array.
* Repeated elements are not allowed.
*
* @param sort_method By default is ASC order, but you can specified whatever you want.
*
* The public methods are:
* -set
* -get
* -del
@flopezluis
flopezluis / gist:1197416
Created September 6, 2011 12:30
filter to return the get paremeters
from django import template
register = template.Library()
@register.filter
def get_parameters(request):
"""
Returns the list of get paremeter
"""
parameters = "?"
@flopezluis
flopezluis / gist:1267749
Created October 6, 2011 15:47
Testing heapq
from heapq import heappush, heappop
def heapsort(iterable, priorities={}):
"""
Sorted the secuence according to the priorities
the biggest number is the less prioritary
>>> priorities ={'Como': 1}
>>> sec = ['camino', 'Como', 'test']
>>> heapsort(sec, priorities)
@flopezluis
flopezluis / gist:1270433
Created October 7, 2011 14:52
Yahtzee categories
from itertools import imap, groupby
def get_duplicates(sec):
return [x for x in sec if sec.count(x) > 1]
class SumEquals(object):
"""
Ones, Twos, Threes, Fours, Fives, Sixes:
"""
@flopezluis
flopezluis / DictAsMember.py
Created December 2, 2011 15:55
Simple but useful
class DictAsMember(dict):
def __getattr__(self, name):
"""
From : http://docs.python.org/reference/datamodel.html#object.__getattr__
Called when an attribute lookup has not found the attribute in the usual places
(i.e. it is not an instance attribute nor is it found in the class tree for self).
name is the attribute name
http://stackoverflow.com/questions/8709975/overwrite-in-python
"""
value = self[name]
@flopezluis
flopezluis / gist:1880114
Created February 22, 2012 00:17
get the last element of a generator (python)
#modification of http://stackoverflow.com/questions/5983265/pythonic-way-of-determining-if-the-current-element-is-the-first-or-last-element
def annotate_last_item(gen):
prev_val = gen.next()
for val in gen:
yield False, prev_val
prev_val = val
yield True, prev_val