Skip to content

Instantly share code, notes, and snippets.

View titanjer's full-sized avatar
🏠

Titan Lin titanjer

🏠
  • Taiwan
View GitHub Profile
#!/bin/bash
set -o errexit
set -o nounset
if [[ ${#} -ne 1 ]]
then
echo "Usage: ${0} upstart-conf-file" >&2
exit 1
fi
#!/usr/bin/env bash
# Pre-requisites
sudo apt-get -y update
sudo apt-get --no-install-recommends -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev vim
# Download and compile Ruby 2.0.0-p0
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
tar -xvzf ruby-2.0.0-p0.tar.gz
def html_decorator(func):
"""
This decorator wraps the output in html.
(From http://stackoverflow.com/a/14647943)
"""
def _decorated(*args, **kwargs):
response = func(*args, **kwargs)
wrapped = ("<html><body>",

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: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