Skip to content

Instantly share code, notes, and snippets.

View shofetim's full-sized avatar

Jordan Schatz shofetim

View GitHub Profile
min_order_adjustment = models.DecimalField(max_digits=12, decimal_places=2, null=True)
@property
def min_order_adjustment(cls):
return cls.min_order_adjustment or 0
products = Product.objects.all()
for p in products:
print unicode(p.cached_primary_image)
-- Doesn't appear to be handled by migrations or syncdb, I don't know why
CREATE TABLE celery_taskmeta (
id integer NOT NULL,
task_id character varying(255) NOT NULL,
status character varying(50) NOT NULL,
result text,
date_done timestamp with time zone NOT NULL,
traceback text,
hidden boolean NOT NULL,
meta text
@contextmanager
def exploding_redis_mutex(key, timeout=10):
r = redis.Redis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=settings.REDIS_DB)
mutex_key = ('mutex', key)
while not r.setnx(mutex_key, datetime.now()):
val = datetime.strptime(r.get(mutex_key), '%Y-%m-%d %H:%M:%S.%f')
if (datetime.now() - val).seconds > timeout:
r.delete(mutex_key)
else:
raise RedisMutexLockedError("'%s' is already locked in the mutex" % (key,))
number = models.PositiveIntegerField(null=False, blank=False, unique=True,
validators=[MinValueValidator(1)])
number = models.PositiveIntegerField(null=False, blank=False, unique=True,
validators=[MinValueValidator(1)])
number= models.PositiveIntegerField(
null=False,
blank=False,
default=72,
validators=[MinValueValidator(1)]
)
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
# Create a new instance of the Firefox driver
#driver = webdriver.Firefox()
driver = webdriver.Chrome()
# go to the google home page
"""
If this proves useful, move it to lib or something more suitable.
The intention is that we need a good API, one that can be used for
developing complex beehive UIs with backbone.js and that can be
exposed to customers.
(See wiki.aquameta.com/Letters_from_a_front-end_guy#5._Stuff_that_hearts_Backbone.js_and_iCanHaz,
there is abunch of stuff that is not yet spec'd)
class BaseView(object):
"""
BaseView provides a class that is instantiated and then
called like a function.
__init__ called without arguments.
You just (must) override the __call__ method.
"""
def __new__(cls, *args, **kwargs):
obj = super(BaseView, cls).__new__(cls)
SELECT
CONCAT('D', dp.id) AS "Drop Point Number",
dp.contact_name AS "Name"
CASE customer.price_level
WHEN 1 THEN 'No'
WHEN 2 THEN 'Yes'
ELSE 'Unknown'
END AS "Wholesale?"
FROM drops_droppoint AS dp
INNER JOIN drops_droppointmanagerpreferences AS pref
SELECT MAX(LENGTH(barcode)) FROM barcodes_barcode; --> 25
SELECT MIN(LENGTH(barcode)) FROM barcodes_barcode; --> 5
SELECT AVG(LENGTH(barcode)) FROM barcodes_barcode; --> 11.1520790674610021
SELECT DISTINCT LENGTH(barcode) FROM barcodes_barcode; -->
length
--------
8
15
25
13