Skip to content

Instantly share code, notes, and snippets.

View mindflayer's full-sized avatar

Giorgio Salluzzo mindflayer

View GitHub Profile
@mindflayer
mindflayer / gist:5444129
Last active December 16, 2015 13:48
I have an index with the following (first file) _mapping, in which I added a dynamic template to assign a custom analyzer (second file) to all fields matching name "meta_*.title" and "meta_*.description". In the last file I added a sample content. Am I right if I say that with this configuration I'm able to perform some "autocomplete" like searc…
{
"webapp_contents": {
"content": {
"dynamic_templates": [
{
"metadata_title": {
"mapping": {
"analyzer": "autocomplete"
},
from datetime import date
s = str(1900630375204)
gender = int(s[0])==1 and 'M' or 'F'
born_date = date(1900+int(s[1:3]), int(s[3:5]), int(s[5:7]))
city_code = int(s[7:])
print gender, borndate, city_code
@mindflayer
mindflayer / gist:6027026
Created July 18, 2013 06:05
For Python group on Facebook
>>> class Fruit(object):
... pass
...
>>> class Apple(Fruit):
... color = None
... def __init__(self, color):
... self.color = color
...
>>> apple_in_my_fridge = Apple('green')
>>> isinstance(apple_in_my_fridge, Apple)
@mindflayer
mindflayer / gist:6524007
Created September 11, 2013 14:00
PHP middleware removal using nginx proxy, JSONP available if GET param callback is available
location ^~ /v02/contenz/ {
if ( $arg_callback ) {
add_header Content-Type application/javascript;
echo_before_body '$arg_callback(';
echo_after_body ');';
}
proxy_pass http://192.168.124.37:8001/;
}
@mindflayer
mindflayer / gist:6648751
Created September 21, 2013 09:00
Compile time dictionary
>>> def a(b, c={}):
... c[b] = b
... print c
...
>>> a('prova')
{'prova': 'prova'}
>>> a('gatto')
{'prova': 'prova', 'gatto': 'gatto'}
>>> a('mela')
{'prova': 'prova', 'mela': 'mela', 'gatto': 'gatto'}
@mindflayer
mindflayer / gist:6690008
Created September 24, 2013 19:28
Create class instance on-the-fly with Python
>>> class Dog(object):
... pass
...
>>> class Cat(object):
... pass
...
>>> def create_object(class_name):
... return getattr(__import__(__name__), class_name)()
...
>>> dog = create_object('Dog')
>>> gencode = {
... 'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M',
... 'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T',
... 'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K',
... 'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R',
... 'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L',
... 'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P',
... 'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q',
... 'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R',
... 'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V',
@mindflayer
mindflayer / index.php
Last active November 21, 2017 23:46
Prerender plain PHP dispatcher file, with X-Prerender-Token
<?php
$uri = $_SERVER["REQUEST_URI"];
$ua = $_SERVER["HTTP_USER_AGENT"];
$static = "home.html"; // your real webapp HTML file (formerly index.html?)
$prerender = 0;
$regex = "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator";
@mindflayer
mindflayer / debug.py
Created March 13, 2015 15:12
TypeError: unhashable type: 'list'
from elasticsearch_dsl import query
q = {'bool': {'must': [{'term': {'customer_id_list': u'es_igames'}}], 'minimum_number_should_match': 1, 'should': [{'query_string': {'minimum_should_match': '30%', 'fields': [u'meta_es_igames.title^5', u'meta_es_igames.es.title^5', u'meta_es_igames.artist_name_list^3', u'meta_es_igames.author_name_list^3', u'meta_es_igames.album_name_list^2', u'meta_es_igames.es.abstract^2', u'meta_es_igames.es.description'], 'default_operator': 'OR', 'use_dis_max': False, 'query': u'debug'}}, [{'term': {u'meta_es_igames.es.title': u'debug'}}, {'prefix': {u'meta_es_igames.es.title': u'debug'}}, {'fuzzy': {u'meta_es_igames.es.title': u'debug'}}, {'term': {'publisher': u'debug'}}, {'prefix': {'publisher': u'debug'}}, {'fuzzy': {'publisher': u'debug'}}, {'term': {'cs_id': u'debug'}}]]}}
query.Q(q)

Keybase proof

I hereby claim:

To claim this, I am signing this object: