Snippets

  • Django isnullfield admin filter

    Made for django 1.11, based on the BooleanFieldListFilter

    class IsNullFieldListFilter(FieldListFilter):
        def __init__(self, field, request, params, model, model_admin, field_path):
            self.lookup_kwarg = '%s__isnull' % field_path
            self.lookup_remove = '%s__exact' % field_path
            self.lookup_val = request.GET.get(self.lookup_kwarg)
            super().__init__(field, request, params, model, model_admin, field_path)
            if (self.used_parameters and self.lookup_kwarg in self.used_parameters and
                    self.used_parameters[self.lookup_kwarg] in ('1', '0')):
                self.used_parameters[self.lookup_kwarg] = bool(int(self.used_parameters[self.lookup_kwarg]))
    
        def expected_parameters(self):
            return [self.lookup_kwarg]
    
        def choices(self, changelist):
            for lookup, title in (
                    (None, 'All'),
                    ('1', 'No'),
                    ('0', 'Yes')):
    
                yield {
                    'selected': self.lookup_val == lookup,
                    'query_string': changelist.get_query_string({self.lookup_kwarg: lookup,}, remove=[self.lookup_remove]),
                    'display': title,
                }

  • Git notes

    Diff to the common ancestor (like github and bitbucket)

       git diff master... < common ancestor
    

    Merge but always resolve towards the branch merging in

    git merge –strategy-option theirs master

  • OPML

    I was playing with the OPML format so I can have an open list of RSS feeds.

    I found Akregator for the desktop, and sparse-rss through f-droid for the phone. Both open source

  • Dumping json from django preserving order and indentation

    In python3 the hash function is randomized by default, hence the need to set the hashseed to 0.

    PYTHONHASHSEED=0 python manage.py dumpdata --indent 2
    

  • Gists copy paste

    SSH PUBKEY

    1. [user@work]$> ssh-keygen generará ~/.ssh/id_[rd]sa{,.pub}

    2. volcar la clave de usuario en el fichero de autorizado [project@work]$> cat id_rsa_usuario.pub » ~/.ssh/authorized_keys

    3. (Opcional) añadir restricciones a la entrada en authorized_keys: from=”trusted.eng.cam.ac.uk”,no-port-forwarding,no-pty ssh-rsa AAA… * from= lista de hosts permitidos:from=”trusted.eng.cam.ac.uk”,no-port-forwarding,no-pty ssh-rsa AAA * el resto de restricciones evita el uso de esas caracteristicas: no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty

    Gentoo

    Para instalar las tarjetas dvb, instalar los paquetes

    media-tv/linuxtv-dvb-apps media-tv/linuxtv-dvb-firmware

    y en /etc/make.conf

    DVB_CARDS="usb-dtt200u usb-wt220u"
    

    snippet fichero zim aleatorio:

    find -name \*.txt | shuf -n1
    

    gender prediction with python

  • DSLs and Towers of Abstraction with Gershom Bazerman at NY Haskell

    https://vimeo.com/72870861 (also reddit link)

  • Introduction to Parsley

    Worry-Free Parsers with Parsley by Allen Short introduces PEGs and Parsley implementation

  • Sphinx 3 oneliners

    Convierte el diccionario en lista de palabrasclave

    cat an4_palabras_clave.dic  |  sed -e "s/^\(\w*\).*/\1/" | uniq 
    

    quitar parentesis

    cat an4_clave.transcription | sed "s/(.*)\(.*\)/\1/"
    

  • Revisando código de python con pylint

    Pylint es una herramienta que sirve para verificar la correctitud de un fichero de código de python.

subscribe via RSS