Skip to content

Instantly share code, notes, and snippets.

View matagus's full-sized avatar
🐿️

Matías Agustín Méndez matagus

🐿️
View GitHub Profile
@matagus
matagus / example.py
Created July 11, 2012 15:15
django transactions
from django.db import transaction
def manual_rollback():
"""Create and rollback using manual transaction calls"""
transaction.enter_transaction_management()
transaction.managed()
try:
try:
create()
error()
@matagus
matagus / newrelic_exception.py
Created July 19, 2012 20:14
recording exception to New Relic using python agent
import sys
import newrelic.agent
try:
# ...
# some code
# ...
except Exception as e:
git branch --merged origin/master | grep -v '\* master' | xargs -l1 git branch -d
@matagus
matagus / postactivate
Created January 24, 2013 18:22
Post activate hook for virtualenvwrapper for loading env variables /paht/to/your/virtualenvs/postactivate
#!/bin/bash
# This hook is run after every virtualenv is activated.
envname="$(basename $VIRTUAL_ENV)"
if [ -e ".env" ]
then
source .env
fi
from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from django.utils.translation import ugettext_lazy as _
from object_images.models import ObjectImage
class ObjectImagesListFilter(SimpleListFilter):
title = _("object images")
parameter_name = "images"
* If you don’t care about the results of a task, be sure to set the ignore_result option, as storing results wastes time and resources:
@celery.task(ignore_result=True)
def mytask(...)
something()
Results can even be disabled globally using the CELERY_IGNORE_RESULT setting.
* Or instead of routing it you could rate limit the task instead, so that only 10 tasks of this type can be processed in a minute (10/m):
Spanish
Portuguese
English
Norwegian
Hungarian
Danish
Finish
French
Italian
Dutch
server {
server_name www.sarasa.com sarasa.com;
if ($host != 'sarasa.com' ) {
rewrite ^/(.*)$ http://sarasa.com/$1 permanent;
}
# Serve an empty 1x1 gif _OR_ an error 204 (No Content) for favicon.ico
location = /favicon.ico {
empty_gif;
@matagus
matagus / rabbitmq.config
Last active January 2, 2018 20:50
a sample rabbitmq config file, tested with RabbitMQ 3.0.2, Erlang R15B01
[
{rabbit, [
{auth_backends, [rabbit_auth_backend_internal]},
{auth_mechanisms, ['PLAIN','AMQPLAIN']},
{backing_queue_module, rabbit_variable_queue},
{cluster_nodes, []},
{collect_statistics, coarse},
{collect_statistics_interval, 5000},
{default_permissions, [<<".*">>,<<".*">>,<<".*">>]},
{default_user, <<"guest">>},
@matagus
matagus / opml.xml
Created March 13, 2014 10:31
planetdjango.org opml file listing all its feeds
<?xml version="1.0"?>
<opml version="1.1">
<head>
<title>Planet Django</title>
<dateModified>Sat, 08 Mar 2014 20:57:35 +0000</dateModified>
<ownerName>Adomas Paltanavičius</ownerName>
<ownerEmail>[email protected]</ownerEmail>
</head>
<body>