This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Thwart off some spam bots by giving them a cup of tea | |
| if ($host = '') { return 418; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for conf in $(find /etc/circus/enabled/ -name *.ini); do \ | |
| circusd $$conf --daemon; \ | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function build_absolute_url(req) { | |
| var protocol = req.socket.encrypted ? 'https' : 'http', | |
| host = req.headers.host || '<no host>'; | |
| return protocol+'://'+host+req.url; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function unsign_value(signature, value) | |
| { | |
| var hmac = crypto.createHmac('sha1', CONFIG.secret_key); | |
| hmac.update(value); | |
| return signature === hmac.digest('hex'); | |
| } |