Skip to content

Instantly share code, notes, and snippets.

View miceno's full-sized avatar

Orestes Sanchez miceno

  • Barcelona, Spain
View GitHub Profile
@miceno
miceno / count.py
Created June 3, 2016 08:05
Aggregated count of categories
# Models
# ColourLabel
# name
#
# Ingredient
# name
# ColourLabelRelation
#
# ColourLabelRelation
@miceno
miceno / import.py
Last active January 2, 2020 18:30 — forked from bmihelac/import.py
Import management command for django-import-export
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import mimetypes
import argparse
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _
from django.core.management.base import BaseCommand
from django.db import transaction
@miceno
miceno / manual-export.py
Created May 11, 2016 14:43
Hand-Manual CSV export
import csv
from ingredients.models import Ingredient
f = csv.writer(open('ing-colors.out','wb'))
f.writerows(Ingredient.objects.filter(
dataset__name="multinet").values_list(
'ingredientdataset__engine_id',
'colour_dominant',
'colour_palette'))
@miceno
miceno / mock_open_with_files.py
Created November 29, 2015 19:32 — forked from romanlevin/mock_open_with_files.py
Mock out the contents of several files with a single patch
from mock import MagicMock
def mock_open_with_files(files):
"""
`files` - a dictionary of the form
{
'/file/path/': 'file body',
...
}
"""
@miceno
miceno / screenrc
Created September 30, 2015 10:51
Screenrc configuration
startup_message off
hardstatus on
hardstatus alwayslastline
# Show current terminals and time
hardstatus string "%{.bW}%-w%{..G}%n %t%{-}%+w %=%{..G} %H %{..Y} %d/%m %C%a"
# allow scrolling
@miceno
miceno / README.md
Last active September 27, 2015 17:26
Email confirmation on Wordpress Contact Form 7

This is a way to validate email by double email fields. Validation is via Javascript.

Files layout is:

../your-child-theme
    |- functions.php
    |- js/email-confirm.js
@miceno
miceno / disable-zoom-gmaps.css
Created August 29, 2015 11:14
Disable scroll wheel zoom on Google Maps iframes.
.google-maps-responsive {
position: relative;
padding-bottom: 75%; // This is the aspect ratio
height: 0;
overflow: hidden;
}
.google-maps-responsive iframe {
position: absolute;
top: 0;
@miceno
miceno / fiddle.response.json
Last active August 29, 2015 14:22
JSON taxonomy
[
{
"name": "SERES VIVOS",
"id": "192",
"photo": "http://www.antcontroldeplagas.es/wp-content/uploads/2013/02/hormigas-head.jpg",
"d": "Las hormigas son bonitas",
"children": [
{
"name": "ANIMALES",
"id": "193",
@miceno
miceno / webserver.sh
Last active August 29, 2015 14:21
Python’s built-in web server
#For example, you can run Python’s built-in server:
python -m SimpleHTTPServer 8888 &
@miceno
miceno / enum-sample.py
Last active August 29, 2015 14:10
Enumeration in python
>>> Status = namedtuple('Status', 'open pending closed')._make(range(3))
>>> Status.open, Status.pending, Status.closed
(0, 1, 2)
>>> class Status:
open, pending, closed = range(3)
>>> Status.open, Status.pending, Status.closed
(0, 1, 2)