Skip to content

Instantly share code, notes, and snippets.

@timw4mail
timw4mail / README.md
Created Jan 12, 2012
PHP __toString() method for debugging
View README.md

Use

In object: $this->__toString(); OR echo $this;

In object, var_dump: $this->__toString('var_dump');

Print out a different object: $class->__toString('print_r', $object);

@timw4mail
timw4mail / index.php
Created Jan 23, 2012
Simple Image gallery script
View index.php
<?php
$files = array_merge(glob("*.jpg"), glob("*.jpeg"), glob("*.png"), glob("*.gif"), glob("*.bmp"), glob("*.swf"));
sort($files);
$num_files = count($files);
if( ! isset($_GET['curr']))
{
$curr_num = 0;
@timw4mail
timw4mail / css-min.php
Created Jan 26, 2012
CSS Minification function
View css-min.php
<?php
//Function for compressing the CSS as tightly as possible
function compress($buffer) {
//Remove CSS comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
//Remove tabs, spaces, newlines, etc.
$buffer = preg_replace('`\s+`', ' ', $buffer);
View cgi.php
<?php
header('Content-type: text/html;charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<title>My First Perl Script</title>
</head>
<body>
<h1>It works!</h1>
@timw4mail
timw4mail / example.html
Created May 8, 2012
Example of javascript cursor trail - updated for modern browsers - based on http://www.java-scripts.net/javascripts/Mouse-Tail-Clock.phtml
View example.html
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="clock">
<div id="Od" style="position:absolute;top:0px;left:0px">
<div style="position:relative">
</div>
@timw4mail
timw4mail / absurd.js
Created Jun 6, 2012
Absurd variable names in Javascript and PHP
View absurd.js
// In javascript, object properties that are not valid for the dot syntax can be defined with square brackets.
// Similar to PHP:
obj[' '] = 'foo';
// While there isn't a direct method to create a variable with a invalid name,
// you can fake it using the document/window variable, or this
this[' '] = 'bar';
@timw4mail
timw4mail / prime_cmd.php
Created Sep 17, 2012
Generating prime numbers
View prime_cmd.php
<?php
set_time_limit(-1);
$primes = json_decode(file_get_contents("prime.json"));
while (TRUE)
{
$i = $primes[count($primes) -1] + 1;
$ip = $i + 999;
View buttons.css
/* IE 9 Mask */
.button_mask {overflow:hidden}
.button_mask, a.button {
display:inline-block;
border-radius:10px;
}
/* General Button Styles */
a.button {
display:inline-block;
@timw4mail
timw4mail / gist:4165315
Created Nov 28, 2012
OpenSQLManager config switches
View gist:4165315
(php/mac)
./configure --prefix=/opt/php-embed/ --exec-prefix=/opt/php-embed/ --enable-embed=static --disable-cgi --with-curl --disable-dom --enable-ftp --enable-mbstring --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pgsql --enable-zip --with-interbase=/Library/Frameworks/Firebird.framework/Libraries/ --enable-phar --enable-debug
(php/linux)
./configure --prefix=/opt/php-embed/ --exec-prefix=/opt/php-embed/ --enable-embed=static --disable-cgi --disable-dom --enable-ftp --enable-mbstring --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pgsql --enable-zip --with-interbase --enable-phar --enable-debug
(wxphp)
./configure --prefix=/opt/php-embed/ --exec-prefix=/opt/php-embed/ --with-wxwidgets=/opt/wxWidgets-svn --with-php-config=/opt/php-embed/bin/php-config
@timw4mail
timw4mail / a.php
Created Nov 29, 2012
Create directory structure in php
View a.php
<?php
/**
* Creates directories based on the array given
*
* @param array $structure
* @param string $path
* @return void
*/
function make_dir_tree($structure, $path=__DIR__)