Skip to content

Instantly share code, notes, and snippets.

View mattrobenolt's full-sized avatar
🀠
πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”

Matt Robenolt mattrobenolt

🀠
πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”πŸ€”
View GitHub Profile
# Thwart off some spam bots by giving them a cup of tea
if ($host = '') { return 418; }
location /xml {
rewrite ^/xml/(.*)$ /$1;
proxy_pass http://xml.test.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 0;
@mattrobenolt
mattrobenolt / jinja.py
Created May 23, 2012 01:48
A CLI interface to Jinja2
#!/usr/bin/env python
"""
jinja2
======
A CLI interface to jinja2.
$ jinja helloworld.tmpl data.json --format=json
$ cat data.json | jinja helloworld.tmpl
$ curl -s http://httpbin.org/ip | jinja helloip.tmpl
$ curl -s http://httpbin.org/ip | jinja helloip.tmpl > helloip.html
for conf in $(find /etc/circus/enabled/ -name *.ini); do \
circusd $$conf --daemon; \
done
var SimpleStream = function(){
Stream.call(this);
this.readable = true;
};
util.inherits(SimpleStream, Stream);
SimpleStream.prototype.write = function(chunk) {
this.emit('data', chunk);
};
SimpleStream.prototype.end = function() {
this.emit('end');
from django.core.cache import cache
class CacheTransactionMiddleware(object):
"""Queues up set and delete calls so they can be executed in bulk.
This middleware queues up cache.set and cache.delete calls into
one big set_many or delete_many call at the end of the request
life cycle. This can drastically improve latency especially when
many many calls are executed in loops.
"""
def qs_to_dict(qs, exclude=(), func=None):
return [model_to_dict(model, exclude, func) for model in qs]
def model_to_dict(model, exclude=(), func=None):
result = {}
fields = [field.name for field in model._meta.fields if field.name not in exclude]
if callable(func):
for field in fields:
key = func(field)
if key:
function build_absolute_url(req) {
var protocol = req.socket.encrypted ? 'https' : 'http',
host = req.headers.host || '<no host>';
return protocol+'://'+host+req.url;
}
var secret_key = 'abcdefghijklmnopqrstuvwxyz';
var hash = crypto.createHash('sha1');
hash.update(secret_key);
console.log(unsign_value('8a8d431c4bee603699e3fd3e9593a3264af0f57c', 'value1'));
function unsign_value(signature, value)
{
var hmac = crypto.createHmac('sha1', hash.digest());
hmac.update(value);
console.log(signature);
function unsign_value(signature, value)
{
var hmac = crypto.createHmac('sha1', CONFIG.secret_key);
hmac.update(value);
return signature === hmac.digest('hex');
}