Skip to content

Instantly share code, notes, and snippets.

@fomigo
fomigo / test-speed.php
Created April 14, 2012 07:02 — forked from opengeek/test-speed.php
Simple benchmark for iterative MODX Chunk parsing
<?php
include 'config.core.php';
include MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
$tstart = $modx->getMicroTime();
@fomigo
fomigo / gist:2382775
Created April 14, 2012 07:59
Russian Plural Form in PHP
<?php
/*
echo plural_form(42, array('арбуз', 'арбуза', 'арбузов'));
*/
function plural_form($n, $forms) {
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]);
}
@fomigo
fomigo / clean dreamhost php files
Created April 19, 2012 07:17
against sweepstakesandcontestsdo.com malware/virus
perl -p -i -e 's/^.*eval\(base64_decode.*7ICB9ICB9\"\)\);\?>//g' `grep -l "eval(base64_decode(" * -R`
@fomigo
fomigo / gist:2654535
Created May 10, 2012 17:17
PDO conection
<?php
function getDb(){
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME;
$dbo = new PDO($dsn, DB_USER, DB_PASS,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
return $dbo;
}
@fomigo
fomigo / jQuery Ajax Request
Created May 14, 2012 05:35
one of the jQuery ajax request
function postComment(data) {
$.ajax({
type: 'POST',
url: 'post_comment.php',
data: data,
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
success: postSuccess,
error: postError
@fomigo
fomigo / PSR-0-final-proposal.md
Created May 22, 2012 06:14 — forked from Thinkscape/PSR-0-final-proposal.md
PSR-0 Final Proposal (PHP Standards Working Group)

PSR-0 Final Proposal (PHP Standards Working Group)

The following describes the mandatory requirements that must be adhered to for autoloader interoperability.

Mandatory:

  • A fully-qualified namespace and class must have the following structure \ <Vendor Name> \ (<Namespace>)* \ <Class Name>
  • Each namespace must have a top-level namespace ("Vendor Name").
  • Each namespace can have as many sub-namespaces as it wishes.
  • Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system.
  • Each "_" character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The "_" character has no special meaning in the namespace.
@fomigo
fomigo / gist:2780263
Created May 24, 2012 08:46
Submiting a form using JQuery
$("#sideform").submit(function() {
var $inputs = $('#sideform :input');
var values = {};
$inputs.each(function() {
values[this.name] = $(this).val();
});
$.ajax({
type: "POST",
url: "/submit-side-form.html",
@fomigo
fomigo / installer.sh
Created June 23, 2012 13:16 — forked from pjkelly/installer.sh
Installing PHPUnit via Pear on Ubuntu Lucid
# Uninstall any pre-existing packaged
# versions of phpunit
sudo apt-get remove phpunit
# Install pear via apt-get
sudo apt-get install php-pear
# Update existing pear channels
sudo pear channel-update pear.php.net
@fomigo
fomigo / SplClassLoader.php
Created July 5, 2012 06:03 — forked from wilmoore/SplClassLoader.php
PHP 5.3 Namespace Autoloader
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.