Skip to content

Instantly share code, notes, and snippets.

View amad's full-sized avatar
🚀
(⌐■_■)

Ahmad Samiei amad

🚀
(⌐■_■)
View GitHub Profile
<?php
class Process_Manager implements Countable
{
protected $processes = array();
protected $is_child = FALSE;
public function count()
{
return count($this->processes);
@amad
amad / logparser.php
Created January 15, 2013 21:52
PHP Daemon
#!/usr/bin/php -q
<?php
/**
* System_Daemon turns PHP-CLI scripts into daemons.
*
* PHP version 5
*
* @category System
* @package System_Daemon
* @author Kevin <kevin@vanzonneveld.net>
@amad
amad / Purge.php
Created February 8, 2013 13:03
Purge is standalone version of well-known Codeigniter xss_clean. just copy and pasted from CI to make it work out of box. Purge::xss_clean($data);
<?php
Class Purge {
static $instance = false;
/**
* IP address of the current user
*
* @var string

Awesome PHP

A list of amazingly awesome PHP libraries, resources and shiny things.

Composer

Composer Related

<?php
/**
* The __halt_compiler() function will stop the PHP compiler when called.
* You can then use the __COMPILER_HALT_OFFSET__ constant to grab the contents of the PHP file after the halt.
* In this example a PHP template is stored after the halt, to allow simple separation of logic from templating.
* The template is stored in a temporary file so it can be included and parsed.
*
* See: https://github.com/bobthecow/mustache.php/blob/dev/src/Mustache/Loader/InlineLoader.php
* http://php.net/manual/en/function.halt-compiler.php
*/
@amad
amad / debug.conf
Created June 26, 2013 14:02 — forked from ziadoz/debug.conf
<VirtualHost *:80>
ServerName example.dev
DocumentRoot /var/www/vhosts/www.example.com/public
# Enable Rewrite Log Debugging (Apache 2.2)
RewriteLog /var/www/vhosts/www.example.com/rewrite.log
RewriteLogLevel 6
# Enable Rewrite Log Debugging (Apache 2.4)
# LogLevel alert rewrite:trace6
@amad
amad / gridComputingOnTheWeb.js
Created August 27, 2013 05:05
Grid computing matrix process
var socket = io.connect('http://grid.moeinhm.ir:3000');
var GridTask = new Worker('matrix.js');
GridTask.postMessage('doIt');
GridTask.onmessage = function(result){
socket.emit('result',result);
GridTask.postMessage('doIt');
};
GridTask.onmessage(result);
<?php
function shutdown_find_exit()
{
var_dump($GLOBALS['dbg_stack']);
}
register_shutdown_function('shutdown_find_exit');
function write_dbg_stack()
{
$GLOBALS['dbg_stack'] = debug_backtrace();
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
@amad
amad / leave_detect.js
Created November 1, 2013 12:31
non standard event for detect user leaving
window.onbeforeunload = function() { return "Message"; };