Skip to content

Instantly share code, notes, and snippets.

View ikks's full-sized avatar

Igor Támara ikks

View GitHub Profile
@ikks
ikks / gist:3775963
Created September 24, 2012 13:31
Django ORM Aggregation samples
#Para contar la cantidad de ventas que se han efectuado:
Cartsale.objects.count()
#Para contar el precio promedio del valor de los artículos vendidos:
CartProduct.objects.aggregate(Avg('price'))
#Para obtener la cantidad de productos que se han vendido:
CartProduct.objects.aggregate(Sum('quantity'))
#Para obtener la cantidad de compras registradas a nombre de un mismo correo:
@ikks
ikks / gist:3776116
Created September 24, 2012 14:05
annotate with a relation
CartSale.objects.annotate(Count('products'),Sum('products__quantity'))
@ikks
ikks / transpo.sh
Created April 7, 2014 13:28
compile translation messages of all translatable django applications
#!/bin/bash
# This script will compile the translation messages of all translatable django applications
# Author: AxiaCore S.A.S. http://axiacore.com
langs="es"
a=`ls -l | grep ^d | awk '{print $9}'`;
curdir=`pwd`
for i in $a
do
@ikks
ikks / gist:10922596
Created April 16, 2014 19:17
md5constructor for Django 1.6
from django.utils.hashcompat import md5_constructor
# Replace by
from hashlib import md5 as md5_constructor
# Even better, take a look at
# https://github.com/justquick/django-native-tags/pull/13/files
@ikks
ikks / 0_reuse_code.js
Created July 16, 2014 14:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ikks
ikks / fast_clicker_for_microview
Created July 25, 2014 02:52
Counter for Arduino when pressing a Button
#include <MicroView.h> // include MicroView library
int buttonPin = A0; // push button pin
int buttonState = 0; // variable to store the pushbutton status
int counter = 0; // counts the number of clicks
int current = 0; // holds the current state
int ticks = 0; // cycle counter
int current_ticks = 0; // Last ticks when the button was released
int doubleclick_max = 50; // topmost double click, if you can't do better call someone younger :P
int difference = 0; // Your record in double click
@ikks
ikks / avoid_fast_click_admin.js
Created August 1, 2014 12:58
Avoid double click for fast clickers in Django admin
// Make sure you have this in a file invoked from the admin templating system
grp.jQuery(function(){
grp.jQuery.fn.preventDoubleSubmission = function() {
grp.jQuery(this).on('submit',function(e){
var the_form = grp.jQuery(this);
if (the_form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
@ikks
ikks / entities_to_raw.sql
Created August 11, 2014 13:16
Update html entities to raw in postgresql
UPDATE cms_base_page SET content=replace(content, '&Aacute;', 'Á');
UPDATE cms_base_page SET content=replace(content, '&Eacute;', 'É');
UPDATE cms_base_page SET content=replace(content, '&Iacute;', 'Í');
UPDATE cms_base_page SET content=replace(content, '&Oacute;', 'Ó');
UPDATE cms_base_page SET content=replace(content, '&Uacute;', 'Ú');
UPDATE cms_base_page SET content=replace(content, '&Uuml;', 'Ü');
UPDATE cms_base_page SET content=replace(content, '&Ntilde;', 'Ñ');
UPDATE cms_base_page SET content=replace(content, '&aacute;', 'á');
UPDATE cms_base_page SET content=replace(content, '&eacute;', 'é');
UPDATE cms_base_page SET content=replace(content, '&iacute;', 'í');
@ikks
ikks / claiming_mailbox_from_gmail.py
Last active August 29, 2015 14:06
Download headers from a label and filter them
"""With the Gmail API is easy to download all your messages or filter them,
is a good practice to have filters and put them in your own messages, so later you
can get some statistics.
You need to make all the auth dance in order to connect to the API, for development
purposes you'll be ok with the instructions provided by Gmail
https://developers.google.com/gmail/api/v1/reference/users/messages
"""
# Path to the output filename
@ikks
ikks / weekly_report.py
Created September 25, 2014 21:27
An approach to have a weekly report
def weekly(query, weeks, initial, final):
u"""Returns a partitioned result grouped by 7 days.
query: Initial query
weeks: Max Number of weeks
initial: initial part of the week
final: end part of the week
You can use like the following:
previous = weekly(
my_query, 8, 'validated_at__gt', 'validated_at__lte',