Skip to content

Instantly share code, notes, and snippets.

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

Eleni Lixourioti Geekfish

🐝
... 🐝 ... 🐝 ... 🐝 ... 🐝
View GitHub Profile
@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]}
@Geekfish
Geekfish / delete_tags.sh
Last active December 16, 2015 15:59
Mass delete git tags
# [1] Grab all tags from remote and put them in a file removing the last 15
# Last chance to review...
git ls-remote --tags origin | awk '/^.+?\s+([^{}]+)$/ {print ":" $2}' | sed -n -e :a -e '1,15!{P;N;D;};N;ba' > remote_tags.txt
# [2] Delete remote tags
cat remote_tags.txt | xargs git push origin
# [3] Delete all local tags and refetch the ones that remain on the remote
git tag -l | xargs git tag -d
git fetch
@Geekfish
Geekfish / reverse_range_map.py
Created March 26, 2013 11:11
Get a mapping of the reverse values of a given range (1 to 5 here). Improved versions welcome.
{val: range(5, 0, -1)[key] for key, val in enumerate(range(1, 6))}
# {1: 5, 2: 4, 3: 3, 4: 2, 5: 1}
@Geekfish
Geekfish / packages.py
Created January 22, 2013 14:21
see outdated packages
import xmlrpclib
import pip
def check_for_updates():
pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
for dist in pip.get_installed_distributions():
available = pypi.package_releases(dist.project_name)
if not available:
# Try to capitalize pkg name
available = pypi.package_releases(dist.project_name.capitalize())
@Geekfish
Geekfish / continue_or_else.py
Created January 18, 2013 12:51
Continue or else?
foos = [1, 2, 4, 1, 1, 5, 2, 1]
# continue
for foo in foos:
if foo == 1:
print "ONE"
continue
print foo
# else
def most_common_problems():
problems = (
"People that come from PHP",
"Coming up with variable names",
"Off-by-one index calculations",
)
print "The three most common problems in programming are:"
for x in range(1, len(problems)):
print "* %s" % problems[x]