View gist:1373179
# METODOS PARA AJAX | |
def ajax_get_subcategorias(request, id_categoria): | |
try: | |
padre = Categoria.objects.get(id = id_categoria) | |
categorias = padre.getSubcategorias() | |
json = serializers.serialize('json', categorias) | |
return HttpResponse(json, content_type='application/javascript; charset=utf-8') | |
except: | |
return HttpResponseNotFound() | |
<<<<<<< local |
View gist:1865924
def __vote(self,user,up_or_down): | |
if self.user is not user: | |
votes = VoteQuestion.objects.filter(question=self,user=user) | |
if len(votes)>0: | |
vote = votes[0] | |
if vote.score is up_or_down: | |
# el mismo voto | |
return -1 | |
else: | |
vote.score += up_or_down |
View gist:1873617
<script type="text/javascript"> | |
$(window).load(function(){ | |
$(".mensaje img").each(function(i,e){ | |
var je = $(e) | |
if(je.width()>"550"){ | |
je.attr("width","550px"); | |
} | |
}); | |
}); | |
</script> |
View gist:2252157
curl -XPUT 'http://127.0.0.1:9200/test_index/?pretty=1' -d ' | |
{ | |
"mappings" : { | |
"user" : { | |
"properties" : { | |
"user_id" : { | |
"type" : "string", | |
"analyzer" : "simple" | |
}, | |
"last_name" : { |
View gist:2255231
SELECT u.id,u.first_name FROM auth_user u | |
JOIN ( | |
SELECT IF(user1 = 1,Null,user1) res1 ,IF(user2 = 1,Null,user2) res2 | |
FROM auth_user u JOIN friendship f | |
ON (u.id = f.user1 OR u.id=f.user2) | |
WHERE | |
u.id = 1 | |
) t ON (u.id=res1 OR u.id=res2) |
View gist:2304539
//http://stackoverflow.com/questions/587404/java-finding-objects-in-collections | |
//http://stackoverflow.com/questions/122105/java-what-is-the-best-way-to-filter-a-collection | |
// Cat class definition | |
// I'm not kidding, nothing else is needed, but this is other topic | |
class Cat(val age: Int) | |
// With type inference and concise functional constructions | |
val a = Array(new Cat(age=1),new Cat(age=2)) | |
// Filtering 1 year old cats |
View gist:2313644
curl \ | |
-F 'access_token=…' \ | |
-F 'batch=[ | |
{"method": "GET", "relative_url": "me"}, | |
{"method": "GET", "relative_url": "me/friends?limit=50"} | |
]'\ | |
https://graph.facebook.com |
View gist:2313912
curl https://graph.facebook.com \ | |
-F 'access_token=...' \ | |
-F 'batch=[ | |
{"method": "GET", | |
"name" : "get-friends", | |
"relative_url": "me/friends", | |
}, | |
{"method": "GET", | |
"relative_url": "likes/?ids={result=get-friends:$.data.*.id}" | |
} |
View gist:2353715
# From this: | |
content: (post_id,user_name,user_picture)-> | |
li = "<li class='comment-box'><a href='#' class='img tooltip'>" | |
img = "<img src='"+user_picture+"' width='40' height='40'>" | |
tooltip = "<small style='width: 68px; margin-left: -46px; '>"+user_name+"</small></a><section>" | |
form = $("<form></form>") | |
form.attr('action', '/comments/post/') | |
form.attr('method','POST') | |
csrf_value = $("input[name='csrfmiddlewaretoken']").val() | |
form.append($("<input type='hidden' name='csrfmiddlewaretoken' value='"+csrf_value+"'></input>")) |
View ResourceTastypie.py
class Resource(object): | |
""" | |
Handles the data, request dispatch and responding to requests. | |
Serialization/deserialization is handled "at the edges" (i.e. at the | |
beginning/end of the request/response cycle) so that everything internally | |
is Python data structures. | |
This class tries to be non-model specific, so it can be hooked up to other | |
data sources, such as search results, files, other data, etc. |
OlderNewer