This file contains hidden or 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
# -*- coding: utf-8 -*- | |
from django.db import models | |
from django.contrib.auth.models import User | |
class Client(models.Model): | |
user = models.OneToOneField(User, blank=True, null=True, ) | |
name = models.CharField(max_length=8, ) | |
tel = models.CharField(max_length=32, blank=True) | |
email = models.CharField(max_length=32, blank=True) |
This file contains hidden or 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 jenkins_32bits(key): | |
xf = 0xFFFFFFFF | |
key = (key+0x7ed55d16) + (key<<12); key = key&xf | |
key = (key^0xc761c23c) ^ (key>>19); key = key&xf | |
key = (key+0x165667b1) + (key<<5); key = key&xf | |
key = (key+0xd3a2646c) ^ (key<<9); key = key&xf | |
key = (key+0xfd7046c5) + (key<<3); key = key&xf | |
key = (key^0xb55a4f09) ^ (key>>16); key = key&xf | |
return key; |
This file contains hidden or 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
# ref: http://blog.eddie.com.tw/2011/11/18/dash-rocket-vs-fat-arrow-in-coffeescript/ | |
class A | |
constructor: (@msg) -> | |
thin: -> console.log @msg | |
fat: => console.log @msg | |
x = new A("yo") | |
x.thin() # alerts "yo" | |
x.fat() # alerts "yo" |
This file contains hidden or 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 import http | |
try: | |
from django.conf import settings | |
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS | |
XS_SHARING_ALLOWED_METHODS = settings.XS_SHARING_ALLOWED_METHODS | |
XS_SHARING_ALLOWED_HEADERS = settings.XS_SHARING_ALLOWED_HEADERS | |
XS_SHARING_ALLOWED_CREDENTIALS = settings.XS_SHARING_ALLOWED_CREDENTIALS | |
except AttributeError: | |
XS_SHARING_ALLOWED_ORIGINS = '*' |
This file contains hidden or 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 CORSResource(object): | |
""" | |
Adds CORS headers to resources that subclass this. | |
""" | |
def create_response(self, *args, **kwargs): | |
response = super(CORSResource, self).create_response(*args, **kwargs) | |
response['Access-Control-Allow-Origin'] = '*' | |
response['Access-Control-Allow-Headers'] = 'Content-Type' | |
return response |
This file contains hidden or 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 scrapy import log | |
from scrapy.item import Item | |
from scrapy.http import Request | |
from scrapy.contrib.spiders import XMLFeedSpider | |
def NextURL(): | |
""" | |
Generate a list of URLs to crawl. You can query a database or come up with some other means | |
Note that if you generate URLs to crawl from a scraped URL then you're better of using a |
This file contains hidden or 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 YourResource(ModelResource): | |
def wrap_view(self, view): | |
""" | |
Wraps views to return custom error codes instead of generic 500's | |
""" | |
@csrf_exempt | |
def wrapper(request, *args, **kwargs): | |
try: | |
callback = getattr(self, view) |
This file contains hidden or 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
Sam command helpers for acme-sac to avoid some manual | |
editing when converting Python to CoffeeScript. | |
Imperfect and incomplete, check manually after use. | |
1. Reduce indentation to half (4->2) | |
2. Remove colons at the end of common statements | |
3. Rename elif to else if | |
4. Change function definitions to arrow declarations | |
5. Change python ranges to array ranges |
This file contains hidden or 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
""" | |
Git Repo: | |
branches | |
dev | |
worker | |
production | |
master | |
dev |
This file contains hidden or 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
ALTER TABLE cpi_product_log ADD NO_SALE_PRICE smallint(5) unsigned AFTER SALE_PRICE; | |
UPDATE cpi_product_log SET NO_SALE_PRICE = 0; | |
ALTER TABLE cpi_product_log DROP SCRAPY_ID; | |
ALTER TABLE cpi_product_log ADD SHIPMENT_COST_T double AFTER SHIPMENT_COST; | |
UPDATE cpi_product_log SET SHIPMENT_COST_T=CAST(SHIPMENT_COST, DOUBLE) | |
ALTER TABLE cpi_product_log DROP SHIPMENT_COST; | |
ALTER TABLE cpi_product_log change SHIPMENT_COST_T SHIPMENT_COST double; |
OlderNewer