iptables -A INPUT -s 31.2.41.8 -j DROP
This file contains 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
<?php | |
// dangerously simple PHP regular expression URL router | |
// requires a mod_rewrite like "RewriteRule . /index.php [L]" | |
function get($url, $callback) { | |
$matches = array(); | |
if (preg_match('~' . $url . '~', $_SERVER['REQUEST_URI'], $matches)) { | |
echo call_user_func_array($callback, $matches); | |
die(); | |
} |
This file contains 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
# -*- coding: utf-8 -*- | |
from django.contrib.auth.decorators import login_required | |
from django.utils.cache import patch_response_headers | |
from django.utils.decorators import method_decorator | |
from django.views.decorators.cache import cache_page, never_cache | |
from django.views.decorators.csrf import csrf_exempt | |
class NeverCacheMixin(object): | |
@method_decorator(never_cache) |
This file contains 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 | |
# The Delicious API only returns 1000 bookmarks at a time. | |
# The web export returns them all in the output file. | |
# | |
# To use: | |
# 1. Install requests: http://python-requests.org | |
# under ubuntu | |
# - install pip : | |
# sudo apt-get install python-pip |
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Whoosh backend for haystack that implements character folding, as per | |
http://packages.python.org/Whoosh/stemming.html#character-folding . | |
Tested with Haystack 2.4.0 and Whooch 2.7.0 | |
To use, put this file on your path and add it to your haystack settings, eg. |
This file contains 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
<?php $span = isset($span) ? $span : 8; ?> | |
<?php $page = isset($this->request->params['named']['page']) ? $this->request->params['named']['page'] : 1; ?> | |
<div class="pagination"> | |
<ul> | |
<?php echo $this->Paginator->prev( | |
'← ' . __('Previous'), | |
array( | |
'escape' => false, | |
'tag' => 'li' | |
), |
This file contains 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
# pfreixes, 2012-07-27 | |
# Add to /etc/bash_completion.d/supervisorctl | |
_supervisor() | |
{ | |
local cur prev opts base | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" |
This file contains 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
""" | |
Simple example on how to inject a custom user parameters onto a formset | |
and its forms. | |
curry(): https://github.com/django/django/blob/1.4.3/django/utils/functional.py#L9 | |
Another answer on: | |
http://stackoverflow.com/questions/622982/django-passing-custom-form-parameters-to-formset | |
""" |
This file contains 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
import os | |
import random | |
from scrapy.conf import settings | |
class RandomUserAgentMiddleware(object): | |
def process_request(self, request, spider): | |
ua = random.choice(settings.get('USER_AGENT_LIST')) | |
if ua: | |
request.headers.setdefault('User-Agent', ua) | |
class ProxyMiddleware(object): |
Now located at https://github.com/JeffPaine/beautiful_idiomatic_python.
Github gists don't support Pull Requests or any notifications, which made it impossible for me to maintain this (surprisingly popular) gist with fixes, respond to comments and so on. In the interest of maintaining the quality of this resource for others, I've moved it to a proper repo. Cheers!
OlderNewer