Skip to content

Instantly share code, notes, and snippets.

@copitux
copitux / datastructures.py
Last active December 23, 2015 04:48
DotNestedDict
class DotNestedDict(dict):
"""
Working with nested dicts (common with mongodb resources) in
a easy way
nested = DotNestedDict({
'lvl1': {'lvl2': {'lvl3': 'here'}},
'collection': [0, 1, 2, 3, {'nested': 4}],
})
@copitux
copitux / unite.ctrl-p.vim
Created September 4, 2013 08:41
unite.ctrl-p
" Ctrl-p behaviour {{{
nnoremap <Leader><Leader> :Unite -start-insert file_rec/async<CR>
call unite#filters#matcher_default#use(['matcher_fuzzy'])
call unite#filters#sorter_default#use(['sorter_reverse'])
call unite#custom#source('file_mru,file_rec,file_rec/async,grep,locate',
\ 'ignore_pattern', join(['\.git/', 'tmp/', 'bundle/'], '\|'))
let g:unite_prompt = '>>> '
let g:unite_winheight = 15
@copitux
copitux / filters.py
Last active December 18, 2015 11:09
Iso 8601 DateTimeFilter to Django Rest Framework and django-filter
"""
The MIT License (MIT)
Copyright (c) <2013> <David Medina>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@copitux
copitux / routers.py
Created June 13, 2013 07:15
App router to Django Rest Framework 2.3.5
from django.core.exceptions import ImproperlyConfigured
from django.db.models import get_app
from django.utils.importlib import import_module
from rest_framework.routers import DefaultRouter
from rest_framework.urlpatterns import format_suffix_patterns
class App(DefaultRouter):
"""

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@copitux
copitux / High concurrency.md
Created April 8, 2013 07:53
[Spanish] High concurrency. Ando jugando con estas tecnologías y los conceptos pueden estar equivocados. Fork y corrige si ves algo raro sin dudarlo!

High concurrency

threading, multiprocessing, eventloop, coroutines, celery, twisted, gevent, libevent, eventlet, libev, epoll, select, kqueue, greenlet ...

Aquí el fin último es la asincronia, no bloquear la aplicación/ejecución y para ello nos apoyamos en la concurrencia y paralelismo. También conocido como asyncronous I/O

En aplicaciones web donde networking I/O está a la orden del día, sumado a alto rendimiento (x000 request/sec) soluciones como gevent se hacen necesarias.

Clasics

@copitux
copitux / wsse.py
Created February 25, 2013 13:42
Extend soap lib suds: UsernameToken with password digest
from base64 import b64encode
from suds.wsse import UsernameToken
try:
from haslib import sha1
except:
from sha import new as sha1
class Noun(object):
def __call__(self):
pass
verb = Noun()
verb()
@copitux
copitux / Doc.rst
Created September 24, 2012 22:20
Django, Django forms and Django rest framework: Payload validation

Django request flow

-------------------------------                         ------------------ Django --------------------
| Browser: GET /udo/contact/2 |    === wsgi/fcgi ===>   | 1. Asks OS for DJANGO_SETTINGS_MODULE      |
-------------------------------                         | 2. Build Request (from wsgi/fcgi callback) |
                                                        | 3. Get settings.ROOT_URLCONF module        |
                                                        | 4. Resolve URL/view from request.path      | # url(r'^udo/contact/(?P<id>\w+)', view, name='url-identifier')
                                                        | 5. Apply request middlewares               | # settings.MIDDLEWARE_CLASSES
@copitux
copitux / gist:3169546
Created July 24, 2012 11:56
Decorator with args
class decorator(object):
def __init__(self, easy_args, with=1, objects=2, decorators=3)
self.easy_args = easy_args
# ...
def __call__(self, func):
@wraps(func) # django.utils.functionals.wraps or functools.update_wrapper (easy debug)
def wrapper(*args, **kwargs):
if self.do_something_with_my_args():