Skip to content

Instantly share code, notes, and snippets.

@podados
podados / gist:3780330
Created September 25, 2012 06:42
find and replace
grep -rl "this" . | xargs sed -i "s/this/that/g"
@podados
podados / gist:3744512
Created September 18, 2012 17:35
Distribute a python library as a "zipped egg" directory
#!/bin/sh
##########################################################
# Distribute a python library as a "zipped egg" directory
##########################################################
# build an egg using a temporary dist directory and keeping the build directory
tmpdir="/tmp/pybuild-$(date +%Y-%m-%d-%H-%M-%S)"
mkdir $tmpdir
python setup.py bdist_egg --keep-temp --dist-dir $tmpdir
@podados
podados / gist:3696059
Created September 11, 2012 04:58
fix apt-get signature fails
apt-get clean
cd /var/lib/apt
mv lists lists.old
mkdir -p lists/partial
apt-get clean
apt-get update
@podados
podados / gist:3085555
Created July 10, 2012 19:05
Dynamic django forms example
from django import forms
from django.contrib import admin
from .models import SphinxDocument, EpydocDocument
CATEGORY_CHOICE_FIELD = forms.ModelChoiceField(
Category.objects.all(),
label = "Category",
)
@podados
podados / gist:3074680
Created July 9, 2012 06:53
Set git branch to track upstream branch
# if you want to do `git push` rather than `git push codebase` where codebase is the remote
git branch --set-upstream master codebase/master
@podados
podados / gist:3009537
Created June 28, 2012 06:42
Python descriptor for lazy memoized attributes
class Lazy(object):
def __init__(self, attr):
self.parts = attr.split('.')
self.cachedname = '__' + '__'.join(self.parts)
def __get__(self, obj, type=None):
try:
attr = obj.__dict__[self.cachedname]
except KeyError:
@podados
podados / gist:3009430
Created June 28, 2012 06:08
Python descriptor for lazy memoized attributes
class Lazy(object):
def __init__(self, attr):
parts = attr.split('.')
self.parts = tuple(parts[:-1])
self.attr = parts[-1]
self.cachedname = '__' + '__'.join(self.parts)
def __get__(self, child, type=None):
try:
@podados
podados / gist:2887196
Created June 7, 2012 07:35
replace Django old style {% url %} with future (1.3) versions
grep -rl "{% url [^'\"]" . | xargs sed -i "s/{% url \([-_:a-zA-Z0-9]\+\) /{% url '\1' /g"
@podados
podados / myproject.conf
Created May 10, 2012 18:46
django-supervisor upstart script
#/etc/init/myproject.conf
description "myproject"
start on runlevel [2345]
stop on runlevel [!2345]
env RUN_AS_USER=root
env VENV=/www/myproject.env
env CMD="$VENV/bin/python $VENV/myproject/manage.py supervisor"
@podados
podados / es.sh
Created April 21, 2012 07:35 — forked from aaronshaf/es.sh
Install ElasticSearch on Ubuntu 11.04
cd /tmp
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.2.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /opt
curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz
mv *servicewrapper*/service /opt/elasticsearch/bin/