Skip to content

Instantly share code, notes, and snippets.

@timw4mail
timw4mail / GetSet.php
Created April 16, 2014 19:51
Trait for naive getter/setter methods
<?php
/**
* Trait to get rid of naive getter/setter boilerplate
*/
trait GetSet
{
/**
* Dynamically create getters/setters
@timw4mail
timw4mail / custom_error_handler.php
Created December 18, 2013 21:22
Catching errors
<?php
/**
* Function to run on script shutdown
* -used to catch most fatal errors, and
* display them cleanly
*
* @return void
*/
function shutdown()
@timw4mail
timw4mail / images.php
Created November 4, 2013 21:20
mal-api script for theme images
<?php
function do_curl($url, $options=array())
{
$cookie = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init($url);
//Use the user's User Agent and Cookies
$opts= array(
CURLOPT_USERAGENT => "Tim's List Image Updater",
CURLOPT_COOKIEJAR => $cookie,
@timw4mail
timw4mail / loops.php
Created October 9, 2013 18:24
Loops and references
<?php
// Normal foreach loop
foreach($foo as $bar)
{
...
}
// Foreach with reference
foreach($foo as &$bar)
@timw4mail
timw4mail / time.js
Created February 8, 2013 21:59
Bookmarket for calculating time differences
javascript:(function(doc){
"use strict";
var $ = function(id){
return doc.getElementById(id);
};
var html = '<div id="tc_form_wrapper"> \
<input type="number" id="tch1" size="3" /> : <input type="number" id="tcm1" size="3" /> \
<button id="tc_plus">+</button> \
@timw4mail
timw4mail / a.php
Created November 29, 2012 21:37
Create directory structure in php
<?php
/**
* Creates directories based on the array given
*
* @param array $structure
* @param string $path
* @return void
*/
function make_dir_tree($structure, $path=__DIR__)
@timw4mail
timw4mail / gist:4165315
Created November 28, 2012 22:50
OpenSQLManager config switches
(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 / buttons.css
Created October 16, 2012 18:21
CSS 3 Buttons
/* 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 / prime_cmd.php
Created September 17, 2012 20:18
Generating prime numbers
<?php
set_time_limit(-1);
$primes = json_decode(file_get_contents("prime.json"));
while (TRUE)
{
$i = $primes[count($primes) -1] + 1;
$ip = $i + 999;
@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';