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
var x = [1,2,3] | |
//back to front | |
while(x.length){ | |
var value = x.pop(); | |
console.log(value); | |
} | |
//array is now empty, lets replace it | |
var x = [1,2,3] |
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 django.db import models | |
class QuerySetManager(models.Manager): | |
"""Add new QuerySet methods using a Model inner class | |
Reference: | |
http://djangosnippets.org/snippets/734/ | |
""" |
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
""" Inherit SafeReadOnly for safe access to mutable objects on classes | |
* Deep copy of mutable attributes on accessing uninstantiated class | |
* No assignment to class attributes on uninstantiated class | |
* Deep copy of mutable attributes when class is instantiated | |
""" | |
from collections import Hashable |
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
expire_deltas = { | |
'minutes': frdelta.FWD_MIN, | |
'hours' : frdelta.FWD_HR, | |
'days': frdelta.FWD_DAY, | |
'months': frdelta.FWD_MO, | |
'years': frdelta.FWD_YR, | |
} | |
def GetExpireDate(expire_date='months', now=None): | |
"""Convert expire_date arguments to date |
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
Copyright (c) 2012, Michael A. Jackson | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without modification, | |
are permitted provided that the following conditions are met: | |
* Redistributions of source code must retain the above copyright notice, this | |
list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright notice, |
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
"""Floored Relative Delta(frdelta) | |
This module contains ready-made relativedeltas. The kwargs class contains | |
all the key word arguments used to create the relativedeltas | |
All relativedeltas are floored, ie. all lesser absolute information is set | |
to zero. | |
If you need more than one forward(FWD) or backward(BWD), use multiplication: | |
This: |
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 DefaultKwargs(**init_kwargs): | |
"""Decorator factory for passing default kwargs to the decorated function. | |
Returns: | |
decorator function | |
""" | |
def decorator(func): | |
"""Recieves a function, then wraps it with wrapper_func |
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
# Taken from http://taketwoprogramming.blogspot.com/2009/06/subclassing-jsonencoder-and-jsondecoder.html | |
class DateTimeAwareJSONEncoder(JSONEncoder): | |
""" | |
Converts a python object, where datetime and timedelta objects are converted | |
into objects that can be decoded using the DateTimeAwareJSONDecoder. | |
""" | |
def default(self, obj): | |
if isinstance(obj, datetime): | |
return { |
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 django.core.handlers.wsgi import WSGIRequest | |
from StringIO import StringIO | |
from django.contrib.auth.models import AnonymousUser | |
def GetFakeRequest(path='/', user=None): | |
""" Construct a fake request(WSGIRequest) object""" | |
req = WSGIRequest({ | |
'REQUEST_METHOD': 'GET', | |
'PATH_INFO': path, | |
'wsgi.input': StringIO()}) |
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
class C(object): | |
def __init__(self, x=None): | |
self.x = x | |
@property | |
def x(self): | |
return self._x | |
@x.setter |