Skip to content

Instantly share code, notes, and snippets.

View t0ster's full-sized avatar
🏠
Working from home 🇺🇦

Roman Dolgiy t0ster

🏠
Working from home 🇺🇦
View GitHub Profile
class Null(object):
def __repr__(self):
return "<Null>"
def __str__(self):
return ''
def __nonzero__(self):
return False
pyt@worker3:~/ab-buildout$ git diff temp
diff --git a/ab/apps/advert/forms.py b/ab/apps/advert/forms.py
index 608237e..e80f156 100755
--- a/ab/apps/advert/forms.py
+++ b/ab/apps/advert/forms.py
@@ -885,11 +885,6 @@ class Search_form(forms.Form):
regions.append(self.cleaned_data["%s%i"%( 'country', i)])
elif self.cleaned_data["%s%i"%( 'region', i)]:
regions.append(self.cleaned_data["%s%i"%( 'region', i)])
- try:
pyt@worker2:~/ab-buildout$ git diff HEAD
diff --git a/ab/apps/advert/forms.py b/ab/apps/advert/forms.py
index 608237e..e80f156 100755
--- a/ab/apps/advert/forms.py
+++ b/ab/apps/advert/forms.py
@@ -885,11 +885,6 @@ class Search_form(forms.Form):
regions.append(self.cleaned_data["%s%i"%( 'country', i)])
elif self.cleaned_data["%s%i"%( 'region', i)]:
regions.append(self.cleaned_data["%s%i"%( 'region', i)])
- try:
Traceback (most recent call last):
File "/Users/t0ster/Documents/workspace/ab-buildout/bin/nosetests", line 63, in <module>
nose.run_exit()
File "/Users/t0ster/.buildout/eggs/nose-0.11.4-py2.7.egg/nose/core.py", line 117, in __init__
**extra_args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/Users/t0ster/.buildout/eggs/nose-0.11.4-py2.7.egg/nose/core.py", line 134, in parseArgs
self.config.configure(argv, doc=self.usage())
File "/Users/t0ster/.buildout/eggs/nose-0.11.4-py2.7.egg/nose/config.py", line 324, in configure
@t0ster
t0ster / gist:747672
Created December 19, 2010 20:48
Playing with datamapper
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
# An in-memory Sqlite3 connection:
DataMapper.setup(:default, 'sqlite::memory:')
# Defining models
class Post
include DataMapper::Resource
def check_attr(obj, attr_name):
"""
*Example*:
if `obj` has 'one__two__three' attribute and
`attr_name` is 'one' this will return 'one',
if `attr_name` is 'one__two__three__four' will return
'one__two__three'
>>> class C(object): pass
def raskolbas(iterable, r):
"""
>>> raskolbas(['one', 'two', 'three', 'four', 'five'], 2)
[['one', 'two'], ['two', 'three'], ['three', 'four'], ['four', 'five']]
"""
l = list(iterable)
return reduce(lambda x, y: (x.append(x[-1][-r+1:] + [y]), x)[-1], l[r:], [l[:r]])
def zakolbas(iterable):
@t0ster
t0ster / resultattr.py
Created December 31, 2010 00:00
proxy class
class ResultAttr(object):
"""
Proxy class, grabbed from
http://code.activestate.com/recipes/496741-object-proxying/
"""
__slots__ = ["_obj", "__weakref__"]
def __init__(self, name, obj, result):
object.__setattr__(self, "_name", name)
object.__setattr__(self, "_obj", obj)
class ResultAttr:
attr_names = set((
'_ResultAttr__value', '_ResultAttr__result', 'name'))
def __init__(self, name, value, result):
"""
Proxy class for `Result` attributes
Arguments:
- `name`: attribute name, for example 'user'
@t0ster
t0ster / gist:792488
Created January 23, 2011 22:02
Python like import in coffee-script
Ti.API.debug "In tango.init"
IMPORTED = []
# Setting sys.path
sys = {}
sys.path = ['site-packages', '.']
class ImportError extends Error
constructor: (@message, @fileName, @lineNumber) ->