Skip to content

Instantly share code, notes, and snippets.

View titanjer's full-sized avatar
🏠

Titan Lin titanjer

🏠
  • Taiwan
View GitHub Profile

This is a general overview (from memory) of the steps I used to install graphite (http://graphite.wikidot.com) on OS X Lion. I think the steps are in order but YMMV. Please fork and fix if you find an error.

Install Python 2.7.2

brew install python

Check your env

$ python --version
upstream php-fpm {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name www.example.com;
rewrite ^ http://example.com$request_uri?;
}
@titanjer
titanjer / gist:5864812
Created June 26, 2013 04:35
add NO_SALE_PRICE delete SCRAPY_ID change SHIPMENT_COST to float
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;
@titanjer
titanjer / gist:5798123
Last active December 18, 2015 14:38 — forked from taras/gist:181654
Scrapy Production/Worker/Dev Setup Fabfile
"""
Git Repo:
branches
dev
worker
production
master
dev
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
@titanjer
titanjer / wrap_view.py
Last active December 18, 2015 08:38 — forked from MacMaru/wrap_view.py
Override Tastypie wrap_view() to return custom (JSON) response
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)
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
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
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 = '*'
# 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"