Skip to content

Instantly share code, notes, and snippets.

View imankulov's full-sized avatar

Roman Imankulov imankulov

View GitHub Profile
@imankulov
imankulov / status.py
Created January 18, 2011 08:53
Status object which can be used as boolean or string (useful to allow / reasonable forbid an action)
"""
Example
Create objects:
>>> status = Status(False, u'You are not allowed to do this')
>>> status = Status(True)
Use objects:
@imankulov
imankulov / htmldiff.py
Created January 24, 2012 04:18
Simple script to show diff between two HTML pages in understandable format
#!/usr/bin/env python
""" Simple script to show diff between two HTML pages in understandable format """
import urllib2, tidy, sys, subprocess
tidy_kwargs = dict(
output_xml=1,
indent=1,
indent_attributes=1,
wrap=80,
char_encoding='raw',
@imankulov
imankulov / htmldiff.py
Created January 24, 2012 04:18
Simple script to show diff between two HTML pages in understandable format
#!/usr/bin/env python
""" Simple script to show diff between two HTML pages in understandable format """
import urllib2, tidy, sys, subprocess
tidy_kwargs = dict(
output_xml=1,
indent=1,
indent_attributes=1,
wrap=80,
char_encoding='raw',
@imankulov
imankulov / gist:2145938
Created March 21, 2012 10:08
Python hook skeleton for gitolite
#!/usr/bin/env python
"""
Python hook skeleton for gitolite.
- Place this file as ~/.gitolite/hooks/common/<hook-name> (i.e. as
~/.gitolite/hooks/common/post-receive)
- Run "gl-setup" in console
- Define a number of function with @hook() decorators inside
Providing such configuration, every function is executed as a hook for a
@imankulov
imankulov / registrar.py
Created April 18, 2012 11:26
Registrar decorator
"""
Registrar decorator can be used to add objects (function and classes) to the
registry.
>>> reg = Registrar()
>>> @reg('foo')
... def foo():
... print 'foo'
...
>>> @reg('bar')
@imankulov
imankulov / memcached_test.py
Created April 27, 2012 04:08
Find out why this script doesn't work (memcached test)
# -*- coding: utf-8 -*-
"""
Why memcached doesn't work?
We observe weird behaviour of the function save_object_to_cache(...)
--------------------------------------------------------------------------------
$ python /tmp/memcached_test.py
A new object <__main__.Wrapper object at 0x925f60c> with value "bar" has been created
@imankulov
imankulov / menu.py
Created April 30, 2012 08:09
Simple django templatetag for menu items
# -*- coding: utf-8 -*-
"""
Templatetag to be used in Django templates along with Twitter bootstrap CSS
library.
To make it work you must make sure that settings.py file contains a line like
this:
TEMPLATE_CONTEXT_PROCESSORS = (
@imankulov
imankulov / nominatim.py
Created May 13, 2012 05:17
Simple wrapper around nominatim geocoding web service
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import httplib2
import urllib
import json
def request(address, email=None, limit=None):
"""
Simple wrapper around nominatim geocoding web service
@imankulov
imankulov / discount_calculator.py
Created May 28, 2012 03:27
Find out why this script doesn't work (discount calculator)
# -*- coding: utf-8 -*-
"""
Why calculator doesn't work and how to fix it?
I expect to see:
$ python /tmp/discount_calculator.py
950.0
@imankulov
imankulov / gist:3074650
Created July 9, 2012 06:42
django-celery patch
diff --git a/djcelery/migrations/0002_v25_changes.py b/djcelery/migrations/0002_v25_changes.py
index f3bb729..7013f7f 100644
--- a/djcelery/migrations/0002_v25_changes.py
+++ b/djcelery/migrations/0002_v25_changes.py
@@ -11,6 +11,10 @@ def ignore_exists(fun, *args, **kwargs):
fun(*args, **kwargs)
except DatabaseError, exc:
if "exists" in str(exc):
+ # don't panic, everything is okay, it's just a hack
+ if db.has_ddl_transactions: