Skip to content

Instantly share code, notes, and snippets.

View Geekfish's full-sized avatar
🐝
... 🐝 ... 🐝 ... 🐝 ... 🐝

Eleni Lixourioti Geekfish

🐝
... 🐝 ... 🐝 ... 🐝 ... 🐝
View GitHub Profile
@Geekfish
Geekfish / template_variables.py
Created December 18, 2013 17:37
Extract variable names from template
from django.template import VariableNode
from django.template.loader_tags import ExtendsNode
def _get_template_variables(template):
"""
Extracts all the variable node tokens of the given template.
This gets worked out recursively by extracting nodes from possible
parent templates via the extension nodes.
"""
@Geekfish
Geekfish / url_monkey_patch.py
Created December 5, 2013 21:28
The only way I found to make urls monkey patching work in a TestCase
class MyTestCase(TestCase):
urls = 'my_app.urls' # This is the default urls module
def setUp(self):
the_monkey_patching()
def tearDown(self):
the_cleanup()
@Geekfish
Geekfish / comma_comma_or.py
Created November 15, 2013 14:18
"a, b, c ... y or z"
import string
' or '.join((', '.join(string.lowercase[:-1]), string.lowercase[-1]))
#!/bin/bash
echo "This script will rebuild a Debian style package (deb) of latest stable"
echo "Nginx. The original deb is from nginx.org apt repository."
echo
echo "This will prompt you yes or no on a few changes to the build as well as"
echo "it will compile and package the latest Google NGX Pagespeed module."
echo
echo "This is built and tested on Ubuntu 12.04 LTS, fresh OS install."
echo "There are no guarantees, and I take no liability if it breaks, but it"
@Geekfish
Geekfish / postgresql-tunnel.pl
Last active December 25, 2015 21:29
Create an ssh tunnel to a postgres db server
#!/usr/bin/perl
# PostgreSQL Tunnel Tool for Mac OS X and Linux
# Copyright (c) 2010 Linode, LLC
# Author: Philip C. Paradis <pparadis@linode.com>
# Usage: postgresql-tunnel.pl [start|stop]
# Access a PostgreSQL database server via an SSH tunnel.
$local_ip = "127.0.0.1";
$local_port = "5433";
@Geekfish
Geekfish / with_context.po
Created September 4, 2013 16:53
Working context
#: insight/generators/calories_altitude.py:15
#, python-format
msgctxt "[calories-altitude]"
msgid "You burn more calories at %(result)s altitudes"
msgstr "Καις περισσότερες θερμίδες σε %(result)s υψόμετρο"
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@Geekfish
Geekfish / pip_git.txt
Last active December 19, 2015 04:58
pip and git trouble
Obtaining django-adaptors from git+git://github.com/Geekfish/django-adaptors.git@bugfix/has_header#egg=django_adaptors-dev (from -r deploy/requirements.txt (line 15))
Updating /Users/username/.virtualenvs/project/src/django-adaptors clone (to bugfix/has_header)
Complete output from command /usr/local/bin/git rev-parse (detachedfrom5b208ac):
fatal: ambiguous argument '(detachedfrom5b208ac)': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:

This example is based on having a cascading setup, where you have a single master, a single "primary" slave, and cascading slaves which are being replicated from the primary slave. For an example of this setup, check out http://bartek.im/blog/2012/12/04/postgresql-92-streaming-primer.html

On the existing master, if accessible, stop postgres.

$ sudo service postgresql stop

And better to be safe than sorry. We can't have two masters running. (I only use this in an automated script. If you're doing this manually, you'd know if it was shutoff)

$ kill -9 `sudo cat /var/lib/postgresql/9.2/main/postmaster.pid | head -n 1` &> /dev/null
@Geekfish
Geekfish / setdefault.py
Created June 3, 2013 11:35
Use setdefault to force an empty list in case you need to iterate over existing values / keys.
my_dict = {}
my_dict['one'] = [1, 2, 3]
my_dict.setdefault('one', []).append(4)
my_dict.setdefault('two', []).append(4)
my_dict.setdefault('three', [])
# In: my_dict
# Out: {'one': [1, 2, 3, 4], 'three': [], 'two': [4]}