Skip to content

Instantly share code, notes, and snippets.

View muratpurc's full-sized avatar

Murat Purç muratpurc

View GitHub Profile
@muratpurc
muratpurc / gist:1234383
Created September 22, 2011 09:02
JS: JSDOC plugin to use for extended documentations
/**
* Replaces occurance of userdefined docblocks within js sourcecode against HTML tags <pre><code>...</pre></code>
*
* Example:
* @xcode
* var foobar = 123456;
* /@xcode
*
* Will be replaced against:
* <pre><code>
@muratpurc
muratpurc / gist:1234410
Created September 22, 2011 09:29
PHP: Traverse object inheritance, creates object tree using the ReflectionClass.
/**
* Builds the class tree, calls itself recursively, if a parent exists.
*
* @param string $name The name of class to create the tree from
* @param int $level Tree level
* @return string The string representation of the tree
*/
function buildClassTree($name, $level=0){
$prefix = str_repeat(' ', ($level * 2));
$tree .= $prefix . $name . "\n";
@muratpurc
muratpurc / gist:1234469
Created September 22, 2011 10:12
PHP: Change mode of folders/files recursively
/**
* Changes mode of folders/files recursively.
*
* @param string $dir The directory to change mode recursively
* @param int $dirMode Folder permissions to set
* @param int $fileMode File permissions to set
* @return void
*/
function mp_recursiveChmod($dir, $dirMode=0775, $fileMode=0775)
{
@muratpurc
muratpurc / gist:1234472
Created September 22, 2011 10:13
PHP: Check the existance of an ressource/file/url on a host (Linkchecker)
/**
* Checks the existance of an ressource/file/url on a host (Linkchecker).
*
* Usage:
* <code>
* $url = 'http://www.google.de/?q=foobar';
* $opt = array('timeout' => 3);
* $result = mp_urlCheck($url, $opt);
* if ($result == false) {
* echo 'ERROR: Errornumber: ' . $opt['errno'] . ', Errormessage: ' . $opt['errstr'];
@muratpurc
muratpurc / gist:1234477
Created September 22, 2011 10:16
PHP: Extended ressource/file/url link check with redirect handling (Linkchecker)
/**
* Checks HTTP Links.
* Based on function phpLinkCheck from Johannes Froemter <j-f@gmx.net>, 2001-04-14.
*
* Usage:
* <code>
* $url = 'http://www.google.de/?q=foobar';
* $res = mp_linkCheck($url);
*
* // key 'Status-Code' will contain the HTTP status code (e.g. 200 or 404).
@muratpurc
muratpurc / gist:1234489
Created September 22, 2011 10:23
PHP: Debug content of passed variable
/**
* Dumps the content of passed variable and returns the result.
*
* @param mixed $var The variable
* @param string $label Additional text to describe the variable
* @param bool $formatted Flag to return formated information
* return string
*/
function mp_dumpVar($var, $label = '', $formatted = true) {
$dump = ($label !== '') ? $label . ":\n" : '';
@muratpurc
muratpurc / gist:1234497
Created September 22, 2011 10:28
PHP: Remove unwanted characters like < > " from passed path value
/**
* Removes unwanted characters like < > " from passed path value
*
* @param string $value The value to clean
* @param string $replaceWith The replacement (empty by default)
* @return string Cleaned path value
*/
function mp_getCleanPathVar($value, $replaceWith = '')
{
$value = (string) trim($value);
@muratpurc
muratpurc / gist:1234502
Created September 22, 2011 10:30
PHP: UTF-8 encoding detection
/**
* Checks, if passed string is utf-8 encoded or not.
*
* @param string $string String to check
* @return int Number of found UTF-8 character
*/
function mp_detectUTF8($string)
{
return preg_match('%(?:
[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
@muratpurc
muratpurc / gist:1234513
Created September 22, 2011 10:39
HTML/CSS: Center a div vertically and horizontally
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>How to center a div vertically and horizontally</title>
<style type="text/css">
#centerBox {
position: absolute;
width: 600px;
@muratpurc
muratpurc / gist:1234515
Created September 22, 2011 10:42
HTML/CSS: Cross-Browser tooltip with CSS
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Example Cross-Browser tooltip with CSS</title>
<style type="text/css"><!--
body {
padding-top:130px;
}
#box {