Steps with explanations to set up a server using:
- virtualenv
- Django
- nginx
- uwsgi
""" | |
Simple proof of concept code to push data to Google Analytics. | |
Related blog post: http://www.canb.net/2012/01/push-data-to-google-analytics-with.html | |
""" | |
from random import randint | |
from urllib import urlencode | |
from urllib2 import urlopen | |
from urlparse import urlunparse | |
from hashlib import sha1 |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>jQuery Mobile Original Source Bookmarklet for Chrome</title> | |
<style type="text/css" media="screen"> | |
body, html, h1 { margin: 0; padding: 0; } | |
html { padding: 20px; background: #ddd; } | |
body { max-width: 600px; margin: 0 auto; padding: 20px; box-sizing: border-box; background: #fff; font-family: Helvetica, arial; box-shadow: rgba(0,0,0,0.2) 0 0 5px } |
from django.contrib.sessions.backends.base import SessionBase, CreateError | |
from django.conf import settings | |
from django.utils.encoding import force_unicode | |
import redis | |
class SessionStore(SessionBase): | |
""" Redis store for sessions""" | |
def __init__(self, session_key=None): | |
self.redis = redis.Redis( |
""" | |
tornado_static is a module for displaying static resources in a Tornado web | |
application. | |
It can take care of merging, compressing and giving URLs ideal renamings | |
suitable for aggressive HTTP caching. | |
(c) [email protected] | |
""" |
""" | |
Backbone.js handler and mongodb based handler for Tornado. | |
`BackboneHandler` handles the sync protocol for Backbone.js. Inherit | |
from the class and implement the model methods: | |
* create_model | |
* update_model | |
* get_model | |
* delete_model | |
* get_collection |
RewriteEngine On | |
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] | |
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] |
worker_processes 2; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
use epoll; | |
} |
import gevent | |
from gevent import monkey | |
monkey.patch_socket() | |
import hashlib | |
import os | |
import redis | |
import zmq | |
from twisted.internet.task import LoopingCall | |
from twisted.internet import reactor | |
from datetime import datetime | |
from time import sleep | |
from multiprocessing import Process | |
class PulseTransmitter(object): | |
def __init__(self): | |
self.context = zmq.Context() |