Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
hgdeoro / views.py
Created February 14, 2012 05:04
Vista necesaria para importar objetos
from django.core import serializers
@login_required
def importar(request):
assert request.method == 'POST'
serialized_text = request.POST['import_json']
for obj in serializers.deserialize('json', serialized_text):
if obj.object.__class__ == ModelOne:
# haz algo con el modelo
@hgdeoro
hgdeoro / import_snippet.html
Created February 14, 2012 05:00
Snippet para agregar un textarea para importar objetos con Django
{% extends "admin/change_list.html" %}
{% load adminmedia admin_list i18n %}
{% load url from future %}
{% block content %}
{{ block.super }}
<div>
<form action="/importar/" method="post">
{% csrf_token %}
<h1 style="margin-top: 1em;">Importar</h1>
@hgdeoro
hgdeoro / named.conf
Created February 9, 2012 19:10
Configuracion basica para Bind 9.8
options {
listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };
directory "/opt/bind-9.8.1-P1/var/named";
dump-file "/opt/bind-9.8.1-P1/var/named/data/cache_dump.db";
statistics-file "/opt/bind-9.8.1-P1/var/named/data/named_stats.txt";
memstatistics-file "/opt/bind-9.8.1-P1/var/named/data/named_mem_stats.txt";
allow-query { localhost; };
recursion yes;
@hgdeoro
hgdeoro / use-named-argument-dir-instead-of-prefix.diff
Created February 4, 2012 18:03
Use 'dir' instaead of 'prefix' when creating temporary files
diff --git a/source4/scripting/python/samba/netcmd/domain.py b/source4/scripting/python/samba/netcmd/domain.py
index 1e26850..176c461 100644
--- a/source4/scripting/python/samba/netcmd/domain.py
+++ b/source4/scripting/python/samba/netcmd/domain.py
@@ -848,9 +848,9 @@ class cmd_domain_samba3upgrade(Command):
eadb = False
elif use_xattrs == "auto" and not s3conf.get("posix:eadb"):
if targetdir:
- tmpfile = tempfile.NamedTemporaryFile(prefix=os.path.abspath(targetdir))
+ tmpfile = tempfile.NamedTemporaryFile(dir=os.path.abspath(targetdir))
@hgdeoro
hgdeoro / check_pipstatus_for_old_bash.sh
Created January 27, 2012 18:44
Checks the exit status of piped commands (for old versions of bash)
function check_pipstatus () {
PSTATUS=( "${PIPESTATUS[@]}" ) # copiamos array
if [ -z "$PSTATUS" ] ; then
echo "ERROR: PIPESTATUS no fue pasado por parametro"
exit 1
fi
if [ ${#PSTATUS[@]} -lt 2 ] ; then
echo "ERROR: PIPESTATUS posee menos de 2 elementos"
exit 1
@hgdeoro
hgdeoro / ntp.conf
Created January 26, 2012 19:40
Config. para servidor NTP
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
@hgdeoro
hgdeoro / patch-django-openid-auth-by-email.diff
Created January 25, 2012 20:52
Parche para django_opendi_auth v0.4, para devolver usuario de Django asociado al EMAIL reportado por OpenId
index 58478ec..31e2833 100644
--- a/src/django_openid_auth/auth.py
+++ b/src/django_openid_auth/auth.py
@@ -30,6 +30,9 @@
__metaclass__ = type
+import logging
+import pprint
+
@hgdeoro
hgdeoro / log_performance_decorator.py
Created January 25, 2012 05:26
Decorator for logging performance info
def log_performance(f):
@wraps(f)
def wrapper(*args, **kwds):
start = datetime.datetime.now()
ret = f(*args, **kwds)
end = datetime.datetime.now()
took = end - start
took = took.seconds + took.microseconds / 1000000.0
logging.info("Call to %s() took: %f secs.", f.func_name, took)
return ret
@hgdeoro
hgdeoro / blueprintcss.py
Created January 24, 2012 16:22
Custom Django filter to convert message levels to valid blueprint css
# -*- coding: utf-8 -*-
from django import template
from django.contrib import messages
register = template.Library()
LEVEL_TO_CSS = {
messages.ERROR: "error",
messages.WARNING: "notice",
@hgdeoro
hgdeoro / test_server_thread_contextmanager.pỳ
Created December 22, 2011 19:30
Context manager for Django's TestServerThread
#
# To be used with 'http://djangosnippets.org/snippets/1570/'
#
@contextmanager
def server_thread(address, port):
server = TestServerThread(address, port)
try:
server.start()
yield server