This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo channel from user nickname.
$ python pub.py foo nickname
PUBLISH to channel #foo
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| # | |
| # Slightly tighter CORS config for nginx | |
| # | |
| # A modification of https://gist.github.com/1064640/ to include a white-list of URLs | |
| # | |
| # Despite the W3C guidance suggesting that a list of origins can be passed as part of | |
| # Access-Control-Allow-Origin headers, several browsers (well, at least Firefox) | |
| # don't seem to play nicely with this. | |
| # |
| -- gets all fields from a hash as a dictionary | |
| local hgetall = function (key) | |
| local bulk = redis.call('HGETALL', key) | |
| local result = {} | |
| local nextkey | |
| for i, v in ipairs(bulk) do | |
| if i % 2 == 1 then | |
| nextkey = v | |
| else | |
| result[nextkey] = v |
| #!/usr/bin/env python | |
| # encoding: utf-8 | |
| import functools | |
| import hashlib | |
| import logging | |
| import tornado.web | |
| import tornado.gen | |
| import tornado.httpclient | |
| import tornado.ioloop |
Mkdown renders Markdown GitHub gists with alternative CSS. Use it to elegantly share gists written in Markdown.
To create your own mkdown URL, append the gist ID in a URL of the form: http://mkdown.com/{GIST ID}. The gist ID is the string at the end of a gist URL.
| # API authentication | |
| from social.apps.django_app.utils import strategy | |
| from rest_framework.authtoken.models import Token | |
| from rest_framework.views import APIView | |
| from rest_framework import parsers | |
| from rest_framework import renderers | |
| from rest_framework.authentication import get_authorization_header | |
| from rest_framework.response import Response |
| // Example | |
| package main; | |
| import ( | |
| "jsonhelper" | |
| "fmt" | |
| ) | |
| func main(){ | |
| jsonValue := []interface {}{ |
| import time | |
| import random | |
| import struct | |
| import select | |
| import socket | |
| def chk(data): | |
| x = sum(x << 8 if i % 2 else x for i, x in enumerate(data)) & 0xFFFFFFFF | |
| x = (x >> 16) + (x & 0xFFFF) |
/etc/ssh/sshd_config on remote machine (remote.example.com):GatewayPorts yes/etc/init.d/sshd restart