Skip to content

Instantly share code, notes, and snippets.

@peteboere
peteboere / batchrename.sh
Created September 2, 2011 18:52
Batch file renaming with bash
# Name:
# batchrename
#
# Synopsis:
# batchrename SEARCH [REPLACE]
#
# Description:
# Bash file renaming function. Can accept regular expression arguments
function batchrename {
@peteboere
peteboere / public_relative_url.php
Created April 18, 2011 11:49
Get a script's public URL relative to the domain
<?php
// Ensure document root superglobal contains no trailing slash
$_SERVER[ 'DOCUMENT_ROOT' ] = rtrim( $_SERVER[ 'DOCUMENT_ROOT' ], '\/' );
// Get current script directory
$this_dir = dirname( __FILE__ );
// Get a public, domain relative, path to current script directory
$this_public = substr( $this_dir, strlen( $_SERVER[ 'DOCUMENT_ROOT' ] ) );
@peteboere
peteboere / request_superglobal.php
Created April 12, 2011 08:49
Tailoring the $_REQUEST superglobal
<?php
/**
* In PHP >= 5.3 ini files you can detemine which of $_COOKIE, $_POST, $_GET variables appear in the
* $_REQUEST superglobal, and the order of precedence in the event of naming collisions.
*
* The following snippet simulates this for versions of PHP < 5.3
*/
$_REQUEST = array_merge( $_GET, $_POST ); // POST overrides GET in name clashes
@peteboere
peteboere / get_current_url.php
Created March 11, 2011 17:26
function to get the current URL
<?php
function get_current_url ( $include_request_uri = true ) {
$https = isset( $_SERVER[ "HTTPS" ] ) && strtolower( $_SERVER[ "HTTPS" ] ) === "on";
$protocol = 'http' . ( $https ? 's' : '' ) . '://';
$host = $_SERVER[ "SERVER_NAME" ];
$port = $_SERVER[ "SERVER_PORT" ];
$request = $include_request_uri ? get_request_uri() : '';
return $protocol . $host . ( $port != 80 ? ":$port" : '' ) . $request;
}
@peteboere
peteboere / wp-bootstrap.php
Created March 9, 2011 17:27
Bootstrap wordpress from any wp installation sub-directory
<?php
if ( !defined( 'ABSPATH' ) ) {
$search = 'wp-load.php';
$limit = 20; // Avoid infinite loop if we're barking up the wrong tree
while ( !file_exists( $search ) and $limit-- ) $search = '../' . $search;
require_once $search;
}
@peteboere
peteboere / get_swf.php
Created March 9, 2011 12:14
function for generating swf object html
<?php
function get_swf ( $url, $attributes = array(), $params = array(), $alt_content = null ) {
$attributes = is_array( $attributes ) ? $attributes : array();
$attributes[ 'width' ] = is_numeric( $attributes[ 'width' ] ) ? $attributes[ 'width' ] : 100;
$attributes[ 'height' ] = is_numeric( $attributes[ 'height' ] ) ? $attributes[ 'height' ] : 100;
$attributes_fmt = " %s=\"%s\"";
$attributes_str = '';
foreach ( $attributes as $name => $value ) {
// ----------------------------------------------------------
// A short snippet for detecting versions of IE:
// Uses a combination of object detection and user-agent
// sniffing.
// ----------------------------------------------------------
// If you're not in IE then:
// ie === NaN // falsy
// If you're in IE then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE: