Skip to content

Instantly share code, notes, and snippets.

@polonskiy
polonskiy / gist:6290981
Created August 21, 2013 06:33
get all memcached keys and values
echo 'stats items' | nc localhost 11211 | while read line; do echo $line | grep -Po 'STAT items:\d+' | grep -Po '\d+'; done | sort -u | xargs -L1 -i echo 'stats cachedump {} 100' | nc localhost 11211 | grep 'ITEM' | sed 's/ITEM \([^ ]\+\) .*/\1/' | xargs -L1 -i echo 'get {}' | nc localhost 11211
<?php
error_reporting(E_ALL);
class O_o
{
public $wth,$mode,$num;
function __construct()
{
$this->wth = "";
$this->mode;

140 byte PHP routing system.

This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.

require('route.php');

// A user profile
route('/(\w+)/profile', function($path, $user)
{

print "Hello " . $user;

Microframework

This is a PHP (5.3+) 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 and settings system
  • named patterns
@polonskiy
polonskiy / gist:6412223
Created September 2, 2013 12:13 — forked from oziks/demo.php
<?php
function flatten($array, $prefix = '') {
$result = array();
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + flatten($value, $prefix . $key . '.');
}
else {
$result[$prefix.$key] = $value;
@polonskiy
polonskiy / gist:6914110
Created October 10, 2013 06:48
php lint
find . -name '*.php' -exec php -l {} \; | grep -v '^No'
<?php
class Server
{
public $master;
public $read = [];
public $write = [];
public $writeBuf = [];
public function listen($address)
@polonskiy
polonskiy / gist:7007016
Created October 16, 2013 12:37
fake smtp server
python -m smtpd -n -c DebuggingServer localhost:2222

140 byte PHP routing system.

This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.

require('route.php');

// A user profile
route('/(\w+)/profile', function($path, $user)
{

print "Hello " . $user;

Composer Workflow

Example of why composer.lock should be version controlled and workflow of how it can be used.

The reason we put ranges in composer.json is so that we can check for updates in our development environment and test our source code works with it BEFORE it goes into production.

The reason we have specific versions of vendors in composer.lock is so that we can version it and install the application into production environments with the versions we have tested while in development. Because of this we never run composer update on a production environment.

Creating an Application