Skip to content

Instantly share code, notes, and snippets.

<?php
function gzip_static($path)
{
if ((extension_loaded('zlib') === true) && (is_file($path) === true))
{
$levels = array();
$content = file_get_contents($path);
foreach (range(1, 9) as $level)
@alixaxel
alixaxel / y.php
Last active October 13, 2016 12:41
Why...
<?php
namespace alixaxel;
class y
{
public static function Coalesce()
{
foreach (func_get_args() as $argument) {
if (isset($argument) === true) {
@alixaxel
alixaxel / Doo.php
Created May 11, 2013 03:27 — forked from eb1024/Doo.php
<?php
function DB($query)
{
static $db = null;
static $result = array();
if (is_file($query) === true)
{
$db = new PDO('sqlite:' . $query, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));

Microframework

This is a PHP microframework based on anonymous functions.

Features

  • requested URLs matched using regular expressions
  • request methods (matches using regular expressions too)
  • differenced FIFO queues for each $priority
  • command line usage
  • backward compatibility
  • integrated Dependency Injection system
  • settings system
/*
So you like the style of impress.js demo?
Or maybe you are just curious how it was done?
You couldn't find a better place to find out!
Welcome to the stylesheet impress.js demo presentation.
Please remember that it is not meant to be a part of impress.js and is
not required by impress.js.
<?php
public static function Segment($key = null, $default = false)
{
static $result = null;
if (is_null($result) === true)
{
if (count($result = explode('/', substr(self::Value($_SERVER, 'PHP_SELF'), strlen(self::Value($_SERVER, 'SCRIPT_NAME'))))) > 0)
{
<?php
function RESTful($root, $convention = '_%s')
{
$root = rtrim(str_replace('\\', '/', realpath($root)), '/');
$segments = preg_replace('~/+~', '/', trim(substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])), '/'));
foreach (range(0, count($segments = explode('/', $segments))) as $i)
{
if (is_file(sprintf('%s/%s.php', $root, $path = implode('/', array_slice($segments, 0, $i)))) === true)
<?php
public static function Highway($path, $throttle = null)
{
if ((count($segments = self::Segment()) > 0) && (preg_match('~/$~', $path = ph()->Disk->Path($path)) > 0))
{
$class = null;
while ((is_null($segment = array_shift($segments)) !== true) && (is_dir($path . $class . $segment . '/') === true))
{
<?php
/*
function Zip($input, $output)
{
if (class_exists('PharData', false) === true)
{
if (is_object($phar = new PharData($output)) === true)
{
if (is_dir($input) === true)
<?php
public static function Enclose($string, $delimiter = null)
{
if (strlen($string = trim($string)) > 0)
{
$string = sprintf('%2$s%1$s%2$s', trim($string, $delimiter), $delimiter);
}
return $string;