Skip to content

Instantly share code, notes, and snippets.

View ikks's full-sized avatar

Igor Támara ikks

View GitHub Profile
@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 / 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 / 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 / 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:3776116
Created September 24, 2012 14:05
annotate with a relation
CartSale.objects.annotate(Count('products'),Sum('products__quantity'))
@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:3775774
Created September 24, 2012 12:45
Cart Sale Model Sample
class CartSale(models.Model):
first_name = models.CharField(
max_length=100,
)
last_name = models.CharField(
max_length=100,
)
date_sale = models.DateTimeField(
auto_now_add=True,
)
@ikks
ikks / gist:3497949
Created August 28, 2012 13:26
Extending a form for use django-autocomplete-light
from django.contrib import admin
import autocomplete_light
from models import Address
class AddressAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(Address)
admin.site.register(Address, AddressAdmin)
@ikks
ikks / gist:3497909
Created August 28, 2012 13:21
Sample of autocomplete_light_registry.py
import autocomplete_light
from cities_light.models import City
autocomplete_light.register(City, search_fields=('search_names',),
autocomplete_js_attributes={'placeholder': 'city name ..'})
@ikks
ikks / gist:3497830
Created August 28, 2012 13:07
extending admin for django-autocomplete-light
{% extends "admin/base.html" %}
{% block extrahead %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
{% include 'autocomplete_light/static.html' %}
{% endblock %}