Skip to content

Instantly share code, notes, and snippets.

Facundo fcasco

  • Greencode Software
  • Santos Lugares, Buenos Aires, Argentina
Block or report user

Report or block fcasco

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fcasco
fcasco / models.py
Created May 25, 2019
Extra SQL en Django (completo)
View models.py
from django.db import models
from django.utils improt timezone
class Person(models.Model):
first_name = models.CharField(max_length=42)
last_name = models.CharField(max_length=42)
birth_date = models.DateField()
email = models.EmailField()
@property
@fcasco
fcasco / models.py
Created May 25, 2019
Extra SQL en Django. 4
View models.py
Person.objects.extra(select={'email_provider': "(COALESCE(substring(email from '@(.*)$'), ''))"}).order_by('email_provider')
@fcasco
fcasco / models.py
Created May 25, 2019
Extra SQL en Django. 3
View models.py
Person.objects.extra(select={'age': "(EXTRACT(year FROM age(birth_date)) :: int)"})\
.values('first_name', 'birth_date', 'age')
@fcasco
fcasco / models.py
Last active May 25, 2019
Extra SQL en Django. 2
View models.py
from django.db import models
from django.utils improt timezone
class Person(models.Model):
first_name = models.CharField(max_length=42)
last_name = models.CharField(max_length=42)
birth_date = models.DateField()
@property
def age(self):
@fcasco
fcasco / models.py
Last active May 25, 2019
Extra SQL en Django. 1
View models.py
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=42)
last_name = models.CharField(max_length=42)
birth_date = models.DateField()
email = models.EmailField()
View fn_in_fn.js
function add_hotel_result(hotel, i, hotels) {
// Crea un nuevo elemento para mostrar los datos del hotel
var $new_hotel_result = $hotels_results.find('.template.hotel_result')
.clone()
.removeClass('template');
$new_hotel_result.find('.hotel_name').html(hotel.hotel_name);
function add_rate_option(rate) {
// Agrega el tipo de habitacion para el hotel
@fcasco
fcasco / dyntest.py
Created Jun 27, 2013
Dynamic test generation (just because I keep forgeting how to do it).
View dyntest.py
import unittest
class TestAutogenerated(unittest.TestCase):
values = [('a', 1), ('be', 20), ('cal', 3), ('dado', 2)]
@staticmethod
def make_test(s, n):
def new_test(self):
@fcasco
fcasco / avoid_twice.py
Created Jun 15, 2013
Context manager to avoid running a task twice
View avoid_twice.py
#!/usr/bin/env python
import unittest
class Avoid_twice():
tasks_filename = '/tmp/avoid_twice'
def __init__(self, task_name):
self.current_task = task_name
@fcasco
fcasco / fzbz.py
Last active Dec 18, 2015
FizzBuzz the Python way with a few magic tricks like decorators, unittest, doctest...
View fzbz.py
#!/bin/env python
# vim: set fileencoding=utf-8 :
"""
http://c2.com/cgi/wiki?FizzBuzzTest
The "Fizz-Buzz test" is an interview question designed to help filter out the 99.5% of programming job
candidates who can't seem to program their way out of a wet paper bag. The text of the programming assignment
is as follows::
"Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of
View gist:5657164
def f(n):
l = []
for i in xrange(n):
l.append(i ** 2)
return l
You can’t perform that action at this time.