This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The book is devoted to metaprogramming. To be brief, metaprogramming is writing code that writes code. | |
Book is divided to two parts: big and small. The big part is devoted to metaprogramming in Ruby directly. | |
But the small little touches metaprogramming in Ruby on Rails. Let's consider the big (and the most | |
important) part. It consists of 5 parts, title as work days of week. When reading the book it assumes, | |
that the reader learns something new every day and mastering metaprogramming in five days. Of course, | |
it's not possible to become a professional in 5 days, or 24 hours or some another short term, Yet the | |
style of narration does not detract from the merits of the book, but vice versa. They support direct | |
dialogue with the reader, proposing to solve some of tasks themselves. The book examines specific examples. | |
But truly say, only in the fifth chapter the author refers directly to the heart of metaprogramming. In the | |
first four chapters he trains the reader to the Ruby conception. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
workon_virtualenv() { | |
if [[ $(git status 2>/dev/null) ]] || [[ $(git status 2>/dev/null) ]] | |
then | |
deactivate >/dev/null 2>&1 | |
$(cat $(hg root 2>/dev/null)/.pvmrc) 1>/dev/null || $(cat $(git rev-parse --show-toplevel 2>/dev/null)/.pvmrc) 1>/dev/null | |
# source $(hg root 2>/dev/null)/.env/bin/activate 2>/dev/null || source $(git rev-parse --show-toplevel 2>/dev/null)/.env/bin/activate 2>/dev/null | |
else | |
deactivate >/dev/null 2>&1 | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git::\1)/' | |
} | |
parse_svn_branch() { | |
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk -F / '{print "(svn::"$1 "/" $2 ")"}' | |
} | |
parse_svn_url() { | |
svn info 2>/dev/null | grep -e '^URL*' | sed -e 's#^URL: *\(.*\)#\1#g ' | |
} | |
parse_svn_repository_root() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[extensions] | |
color = | |
pager = | |
[color] | |
status.modified = cyan bold | |
status.added = green bold | |
status.removed = red bold | |
status.deleted = red bold | |
status.unknown = magenta bold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tee(iterable, n=2): | |
try: | |
iter(iterable) | |
except TypeError: | |
raise Exception("%s isn't iterable, silly boy :)" % iterable) | |
def f(iterable): | |
for i in iterable: | |
yield i | |
return [f(iterable) for i in xrange(n)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def peekable(generator): | |
import types | |
if not isinstance(generator, types.GeneratorType): | |
raise Exception("%s isn't generator, silly girl ;)" % generator) | |
def stop_iterator(func): | |
def wrapper(*args, **kwgs): | |
try: | |
return func(*args, **kwgs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread | |
class Subscriber(object): | |
_instance = None | |
def __new__(cls): | |
if not cls._instance: | |
cls._instance = super(Subscriber, cls).__new__(cls) | |
cls._instance.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from celery import Celery | |
try: | |
import cPickle as pickle | |
except ImportError: | |
import pickle | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_once(func): | |
setattr(func, 'was_launched', False) | |
def wrapper(*args, **kwgs): | |
if getattr(func, 'was_launched'): | |
return | |
setattr(func, 'was_launched', True) | |
return func(*args, **kwgs) | |
return wrapper |
OlderNewer