Skip to content

Instantly share code, notes, and snippets.

View santiagobasulto's full-sized avatar

Santiago Basulto santiagobasulto

View GitHub Profile
# 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
@santiagobasulto
santiagobasulto / gist:1865924
Created February 19, 2012 21:34
Functional programing with python and django
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
@santiagobasulto
santiagobasulto / gist:1873617
Created February 21, 2012 04:16
Reducidor de tamaño para imgs en subdivx
<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>
curl -XPUT 'http://127.0.0.1:9200/test_index/?pretty=1' -d '
{
"mappings" : {
"user" : {
"properties" : {
"user_id" : {
"type" : "string",
"analyzer" : "simple"
},
"last_name" : {
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)
@santiagobasulto
santiagobasulto / gist:2304539
Created April 4, 2012 18:30
Filtering collections on Scala
//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
@santiagobasulto
santiagobasulto / gist:2313644
Created April 5, 2012 19:58
Simple Curl request to fb
curl \
-F 'access_token=…' \
-F 'batch=[
{"method": "GET", "relative_url": "me"},
{"method": "GET", "relative_url": "me/friends?limit=50"}
]'\
https://graph.facebook.com
@santiagobasulto
santiagobasulto / gist:2313912
Created April 5, 2012 20:38
Get all friends likes from facebook
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}"
}
@santiagobasulto
santiagobasulto / gist:2353715
Created April 10, 2012 19:04
Mustache + coffeescript
# 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>"))
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.