Skip to content

Instantly share code, notes, and snippets.

View twidi's full-sized avatar
🕶️

Stéphane "Twidi" Angel twidi

🕶️
View GitHub Profile
class Hashable(models.Model):
hash_method_prefix = 'compute_hash_'
default_hash_method = 'compute_hash_default'
hashable_fields = []
class Meta:
abstract = True
def compute_hash_default(self, field_name, hash_function):

A journey to python 3: porting redis-limpyd

Introduction

A few weeks ago, I - Twidi - made a proposal to talk about redis-limpyd at Pytong.

And it was accepted. But... the main subject of Pytong is "After python 2".

redis-limpyd currently only works on python 2.6 and 2.7, and as I said during my lightning talk at PyconFR in October 2013 (start at 47:50), "porting to python 3 is on it's way"... but the only thing that was done at this time - and it's still the case as I'm writing these lines - was a simple run of the 2to3 command to see the things that needed to be done, by Yohan Boniface, original author of the project.

@twidi
twidi / keybase.md
Created September 22, 2014 20:13
keybase.md

Keybase proof

I hereby claim:

  • I am twidi on github.
  • I am twidi (https://keybase.io/twidi) on keybase.
  • I have a public key whose fingerprint is 3905 1403 EAF3 06A4 0464 18CD E4A4 4103 3000 5942

To claim this, I am signing this object:

@twidi
twidi / manage_dropbox_images.sh
Last active August 29, 2015 14:06
manage_dropbox_images.sh: The goal of this script is to reduce the size of the dropbox folder where are automatically uploaded images taken with a smartphone, by linking to the same images found in other folders (for example if all images of your smartphone are regularly uploaded to a specific folder)
#!/bin/bash
# The goal of this script is to reduce the size of the dropbox folder
# where are automatically uploaded images taken with a smartphone, by
# linking to the same images found in other folders (for example if all
# images of your smartphone are regularly uploaded to a specific folder)
DIR_CHARG=~/Dropbox/Chargements\ appareil\ photo/
DIR_IMG=~/Dropbox/Photos/Images/
### from Exirel
# Ce que je voudrais
SELECT AVG(last_updated_at - created_at) FROM monapp_item;
# Ceci fonctione
Item.objects.extra(select={'delta': 'last_update_at - created_at'})
# Mais pas ça
Item.objects.extra(select={'delta': 'last_update_at - created_at'}).aggregate(Avg('delta'))
@twidi
twidi / About
Last active August 29, 2015 14:17
Find all non-builtins import in a python project
- we use `ack` (`ack-grep`)
- we assume builtins are marked so, or in a `python*` directory in a `lib` one, but not in `*packages*` (`site-packages for example`)
- everything that cannot be imported is not a builtin package
If your python is not in a "lib/pythonX.Y" directory, you can change the path.
PS: on my machine, it works in a virtualenv
@twidi
twidi / dataql_example.py
Created June 15, 2015 16:46
Example file showing how to use dataql
from datetime import datetime, date
from dataql.parser.parsers import DataQLParser
from dataql.solvers.registry import Registry, EntryPoints
# Declare our classes
class User:
users = []
index 1c0e8fa..23b0d4a 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -213,6 +213,7 @@ class Redis(threading.local):
string_keys_to_dict('ZRANGE ZRANGEBYSCORE ZREVRANGE', zset_score_pairs),
{
'BGSAVE': lambda r: r == 'Background saving started',
+ 'BGREWRITEAOF': lambda r: r == 'Background rewriting of AOF file started',
'HGETALL': lambda r: r and pairs_to_dict(r) or None,
'INFO': parse_info,
import threading
import Queue
q = Queue.Queue()
def worker():
while True:
msg = q.get(block=True)
# do stuff with the message
t = threading.Thread(target=worker)
import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed