Skip to content

Instantly share code, notes, and snippets.

@timw4mail
timw4mail / absurd.js
Created June 6, 2012 20:09
Absurd variable names in Javascript and PHP
// 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 / example.html
Created May 8, 2012 16:50
Example of javascript cursor trail - updated for modern browsers - based on http://www.java-scripts.net/javascripts/Mouse-Tail-Clock.phtml
<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 / cgi.php
Created May 4, 2012 20:33
Perl vs 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 / css-min.php
Created January 26, 2012 23:07
CSS Minification function
<?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);
@timw4mail
timw4mail / index.php
Created January 23, 2012 21:32
Simple Image gallery script
<?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 / README.md
Created January 12, 2012 19:35
PHP __toString() method for debugging

Use

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

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

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

@timw4mail
timw4mail / magic.php
Created December 7, 2011 16:36
PHP Magic methods
<?php
/**
* Magic constants
*/
// Current line number of the php file
$current_line_number = __LINE__;
// Current PHP file
@timw4mail
timw4mail / JSObject.php
Created November 30, 2011 20:22
PHP Class for javascript-like objects
<?php
/**
* JSObject
*
* Class for creating object-literal-like contstructs in PHP
*/
class JSObject {
/**
@timw4mail
timw4mail / minify.php
Created November 3, 2011 23:46
HTML Minification
<?php
define('SAFE', 1);
define('EXTREME', 2);
define('EXTREME_SAVE_COMMENTS', 4);
define('EXTREME_SAVE_PRE', 3);
function minify($html, $level=2)
{
switch((int)$level)
<?php
function Zip($source, $destination)
{
if (extension_loaded('zip') === true)
{
if (file_exists($source) === true)
{
$zip = new ZipArchive();