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 / 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 / return-dictionary-aggregated-query
Created September 12, 2014 00:18
A dictionary from a list of tuples
# List of selected categories
selected_categories = [Category.objects.get(name="TERRESTRE"), Category.objects.get(name="MOLUSCOS")]
# Products we want to filter based on the list of selected categories
products = Product.objects.filter(category__in = selected_categories)
# list is a tuple of tuples like ((id1, product_count1), (id2, product_count2), ... , (idn, product_countn))
qs_count = Category.objects.values(‘id’).filter(product__in=products).annotate(Count('product'))
# Get the values
@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)
@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 / 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 / gist:738266
Created December 12, 2010 19:42
Read commandline with DSL CliBuilder
// An example of how to configure the CliBuilder to read command line arguments in Groovy.
def cli = new CliBuilder( usage: 'groovy launcher' )
// Option help
cli.h(longOpt: 'help', 'usage information')
// Option script
cli.s(argName:'script', longOpt:'script', required: true,
args: 1, 'Script filename')
@miceno
miceno / title.groovy
Created December 17, 2010 22:11
Create a String centered and filled with a character
"title".center( 40, "-")
@miceno
miceno / Read formatted file one-liner.groovy
Created December 30, 2010 09:24
Read formatted file one-liner
new File("simple.tab").withReader{r->
line = r.readLine();
println "first line: $line"
r.splitEachLine("\t"){fields->
println "fields on line: $fields"
}
}
@miceno
miceno / reading and parsing xml.groovy
Created January 2, 2011 11:35
Reading XML with Java DocumentBuilder parsing with Java XPath
// Groovy: Reading XML with Java DocumentBuilder parsing with Java XPath
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.*
import org.w3c.dom.Document;
File f= new File( 'data.xml')
// Reading a Document Builder with Java style
@miceno
miceno / table_size.sql
Created January 2, 2011 19:18
Get the size of all tables of a database
mysql -e "show table status" | awk -F'\t' '\
{\
printf ("%-25s %15d\n", $1,$7); \
s+=$7 \
} \
END{ print "resultado: ", s} \
'