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
### Testing if the client is a mobile or a desktop. | |
### The selection is based on the usual UA strings for desktop browsers. | |
## Testing a user agent using a method that reverts the logic of the | |
## UA detection. Inspired by notnotmobile.appspot.com. | |
map $http_user_agent $is_desktop { | |
default 0; | |
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule | |
~*spider|crawl|slurp|bot 1; # bots | |
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes |
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
map $request_uri $cache_valitidy { | |
default 5m; | |
~this-regex-uri 2h; | |
} | |
## Then do like this in the cache definition: | |
proxy_cache_valid 200 301 $cache_validity; | |
## For fastcgi cache. | |
fastcgi_cache_valid 200 301 $cache_validity; |
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
function doHash(str, seed) { | |
var m = 0x5bd1e995; | |
var r = 24; | |
var h = seed ^ str.length; | |
var length = str.length; | |
var currentIndex = 0; | |
while (length >= 4) { | |
var k = UInt32(str, currentIndex); | |
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
## Here's the way to have Nginx return a robots.txt file that disallows all crawling by bots. | |
## This is useful for development and private sites. | |
location = /robots.txt { | |
return 200 "User-agent: *\nDisallow: /\n"; | |
} |
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
; Add this to your php.ini. E.g., to /etc/php5/fpm/php.ini (with PHP-FPM on Debian based systems). | |
; Increase the entropy of your session token. The default setting is 0 (disabled). | |
session_entropy_length = 32 | |
; OS based random data generator as source for entropy. | |
session.entropy_file = /dev/urandom |
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 | |
/** | |
* @file drupal_uid_header.module | |
* @author António P. P. Almeida <[email protected]> | |
* @date Tue Dec 27 2011 | |
* | |
* @brief Sets an HTTP header with the UID (Drupal 6). | |
* | |
*/ |
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
#!/bin/sh | |
set -e | |
# Ping FCGI server. Uses cgi-fcgi program from libfcgi library. | |
# Retrieves the root path (/) from host:port specified on command line. | |
if [ -z "$1" ] ; then | |
echo "Usage: $0 host:port|path/to/socket" >&2 | |
exit 1 | |
fi |
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
### Here's a very simple SOPA blackout page. | |
## Include this at the top of your vhost configuration (server block): 'include /path/to/sopa_blackout.conf;' | |
error_page 503 @sopa; | |
return 503; | |
location @sopa { | |
default_type text/html; | |
return 503 "<!DOCTYPE html><html><head><meta charset='UTF-8'/><style>body{color: white; background-color: black;}</sytle></head><body><center><h1>We're down due to SOPA blackout!</h1></center></body></html>\n"; | |
} |
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 | |
// Integer division in PHP. | |
function div($x, $y) { | |
if ($x == 0) { | |
return 0; | |
} | |
elseif ($y == 0) { | |
return FALSE; | |
} | |
else { |
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 | |
/** | |
* Implements hook_init(). | |
*/ | |
function drupal_microcache_header_init() { | |
drupal_add_http_header('X-Accel-Expires', 0); | |
} // drupal_microcache_header_init |