Skip to content

Instantly share code, notes, and snippets.

@copitux
copitux / gist:1041620
Created June 23, 2011 00:21
Type with models inheritance
##### Test ...
#
# DocumentService(name='document1').save()
# VideoService(name='video1').save()
# DocumentService(name='document2').save()
# VideoService(name='video2').save()
#
# DocumentService.objects.all()
#> [<DocumentService: <class 'test_app.models.DocumentService'>: document1>, <DocumentService: <class 'test_app.models.DocumentService'>: document2>]
#
@copitux
copitux / postactivate
Created July 13, 2011 09:11 — forked from carljm/postactivate
Yo dawg, I heard you like Ruby...
#!/bin/bash
# This hook is run after every virtualenv is activated.
export OLD_GEM_HOME=$GEM_HOME
export GEM_HOME=$VIRTUAL_ENV/gems/
export GEM_PATH=
export PATH=$VIRTUAL_ENV/gems/bin:$PATH
@copitux
copitux / compass.md
Created July 17, 2011 09:12
Directrices compass

1. Instalar compass

Ruby > 1.8   : sudo apt-get install ruby
Ruby gems    : sudo apt-get install rubygems
Compass      : sudo gem install compass

Link compass binary: sudo ln -s /var/lib/gems/1.8/bin/compass/usr/local/bin/compass
or edit COMPASS_BINARY and replace with absolute rute

2. Vistazo rápido a Sass

http://sass-lang.com/tutorial.html

@copitux
copitux / test.py
Created October 29, 2011 00:37
test description to api
import test
test.publish.api()
@copitux
copitux / bookmarks.bash
Created January 23, 2012 13:17
Bookmarks in bash shell
# Source: http://hints.macworld.com/article.php?story=20020716005123797
if [ ! -f ~/.dirs ]; then # if doesn't exist, create it
touch ~/.dirs
fi
alias show='cat ~/.dirs'
save (){
command sed "/!$/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "$@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ;
}
source ~/.dirs # Initialization for the above 'save' facility: source the .sdirs file
@copitux
copitux / gist:1925816
Created February 27, 2012 17:46
modbus tk sample
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import threading
import time
from random import random
lock = threading.Lock()
def thread_safe(func):
@copitux
copitux / gitp2svnp.rb
Created June 8, 2012 08:20 — forked from zbyhoo/gitp2svnp.rb
Simple script converting git patch file into tortoise merge compatible format. Usage: gitp2svnp.rb <git_patch_file>
#!/usr/bin/ruby
if ARGV.length != 1
puts "usage: git2svn <file_name>"
puts " file_name - git patch file name"
exit
end
separator = "\n===================================================================\n"
new_file = false
@copitux
copitux / gist:3003658
Created June 27, 2012 12:04
swap_queryset
class OwnAdmin(admin.ModelAdmin):
...
def swap_queryset(func):
def wrapper(self, request):
own_queryset_method = self.queryset
self.queryset = super(LeaderAdmin, self).queryset
response = func(self, request)
self.queryset = own_queryset_method
return response
return wrapper
@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():
@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