Skip to content

Instantly share code, notes, and snippets.


Santiago Basulto santiagobasulto

View GitHub Profile
View gist:1373179
def ajax_get_subcategorias(request, id_categoria):
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')
return HttpResponseNotFound()
<<<<<<< local
santiagobasulto / gist:1865924
Created Feb 19, 2012
Functional programing with python and django
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
vote.score += up_or_down
santiagobasulto / gist:1873617
Created Feb 21, 2012
Reducidor de tamaño para imgs en subdivx
View gist:1873617
<script type="text/javascript">
$(".mensaje img").each(function(i,e){
var je = $(e)
View gist:2252157
curl -XPUT '' -d '
"mappings" : {
"user" : {
"properties" : {
"user_id" : {
"type" : "string",
"analyzer" : "simple"
"last_name" : {
View gist:2255231
SELECT,u.first_name FROM auth_user u
SELECT IF(user1 = 1,Null,user1) res1 ,IF(user2 = 1,Null,user2) res2
FROM auth_user u JOIN friendship f
ON ( = f.user1 OR
) t ON ( OR
santiagobasulto / gist:2304539
Created Apr 4, 2012
Filtering collections on Scala
View gist:2304539
// 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 / gist:2313644
Created Apr 5, 2012
Simple Curl request to fb
View gist:2313644
curl \
-F 'access_token=…' \
-F 'batch=[
{"method": "GET", "relative_url": "me"},
{"method": "GET", "relative_url": "me/friends?limit=50"}
santiagobasulto / gist:2313912
Created Apr 5, 2012
Get all friends likes from facebook
View gist:2313912
curl \
-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 / gist:2353715
Created Apr 10, 2012
Mustache + coffeescript
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/')
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.