Skip to content

Instantly share code, notes, and snippets.

@pyzen
pyzen / gist:3987597
Created October 31, 2012 15:17 — forked from evildmp/gist:3094281
Set up Django, nginx and uwsgi

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

  • virtualenv
  • Django
  • nginx
  • uwsgi
@pyzen
pyzen / ga.py
Created October 30, 2012 13:35 — forked from canburak/ga.py
blog post: Push data to Google Analytics with Python
"""
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
@pyzen
pyzen / jquery-bookmarklet.html
Created October 23, 2012 11:46 — forked from dcneiner/jquery-bookmarklet.html
jQuery Mobile View Source Bookmarklet Website
<!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 }
@pyzen
pyzen / redis_session_backend.py
Created October 14, 2012 06:47 — forked from mikeyk/redis_session_backend.py
A redis backend for Django Sessions, tested on Django 1.3+
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(
@pyzen
pyzen / tornado_static.py
Created October 7, 2012 09:44 — forked from peterbe/tornado_static.py
tornado_static
"""
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]
"""
@pyzen
pyzen / backbonehandler.py
Created October 5, 2012 05:06 — forked from jamescasbon/backbonehandler.py
Backbone.js handler for tornado and mongodb backed handler
"""
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
@pyzen
pyzen / .htaccess
Created September 29, 2012 06:49 — forked from macek/.htaccess
Redirect without www on Nginx and Engine Yard
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
@pyzen
pyzen / tornado-nginx-example.conf
Created September 23, 2012 11:40 — forked from didip/tornado-nginx-example.conf
Nginx config example for Tornado
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
@pyzen
pyzen / worker3.py
Created September 22, 2012 19:49 — forked from jdmaturen/worker3.py
Redis stats aggregator w/ Gevent
import gevent
from gevent import monkey
monkey.patch_socket()
import hashlib
import os
import redis
@pyzen
pyzen / timer_test.py
Created September 19, 2012 13:09 — forked from taotetek/timer_test.py
Sending timed signals to multiple processes using twisted and zeromq
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()