Directory structure:
src/
Foo.php
Foo/
Exception.php
Excecption/
Unauthorized.php
NotFound.php
Method.php
<?php | |
$cur = $seconds; | |
for( $i = count( $this->multipliers ) - 1; $i >= 0; $i -- ) { | |
$ps = $this->periodSize( $i ); | |
$parts[] = (int) floor( $cur / $ps ); | |
$cur -= $cur - ($cur % $ps); | |
} | |
var_dump($parts); |
require 'mysql2' | |
my = Mysql2::Client.new(:host => 'localhost', :username => 'root', :database=>'test') | |
stmt = my.prepare('INSERT INTO user (salt, password) VALUES(?,?);') | |
salt = "1a7v95zj1xa1l26g80meeaplc7294dp" | |
hashed = "4542511a19a5b18fd6801653ddc97b6e6ef3e855f4736720d791c4f4eed78957c0b5906921725a3ad0d8e98cf6722243f64e552382a37eb839f204d4fe6770ae" | |
stmt.execute(salt, hash) | |
# woops, that should be 'hashed', not 'hash'. |
<?php | |
require('creds.php'); | |
if( isset($creds[$_POST['user']]) && ($creds[$_POST['user']] == md5($_POST['pass'])) ) { | |
echo "Authenticated"; | |
} else { | |
echo <<<_eoi_ | |
<form action="" method="POST"> | |
<input name="user" type="text" /> | |
<input name="pass" type="password" /> |
<?php | |
$dom = new DOMDocument(); | |
// cache of the wikipedia page | |
$dom->loadHTML(file_get_contents('abe.vigoda_cache.html')); | |
foreach($dom->getElementById('persondata')->getElementsByTagName("tr") as $row) { | |
foreach($row->childNodes as $node) { | |
if( $node->hasAttribute('class') ) { | |
var_dump($dom->saveXML($node)); | |
} |
// a complex iterator | |
function gen() { | |
$pagesize = 50; | |
while( $items = $someapi->paginated_operation($pagesize) ) { | |
foreach( $items as $item ) { | |
yield $item; | |
} | |
} | |
} |
<?php | |
// supplied encoding function | |
function stupidEncode($input, $key) { | |
$k = $key; | |
$r = $input; | |
$l = strlen($r); | |
$e = ""; | |
for($i=0; $i < $l; $i++){ |
Directory structure:
src/
Foo.php
Foo/
Exception.php
Excecption/
Unauthorized.php
NotFound.php
Method.php
<? | |
foreach($filters as $pos => $filter) { | |
if( ! $filter instanceof Filter\FilterInterface ) { | |
throw new \InvalidArgumentException( | |
sprintf('Argument 3 passed to %s::%s must be an array of instances of %s, %s given for index %d', | |
__CLASS__, __FUNCTION__, 'Filter\FilterInterface', get_class($filter), $pos) | |
); | |
} | |
} |
<?php | |
class StrTok { | |
const INCL_PREV = 1; // include previous token at beginning of string | |
const INCL_CUR = 2; // include current token at end of string | |
const SKIP_EMPTY = 4; // skip empty strings | |
private $string, $tokens, $flags, $curpos; | |
public function __construct($string, $tokens, $flags=0) { | |
$this->string = $string; |
<?php | |
function int_to_perm($int) { | |
return sprintf( | |
'%s%s%s', | |
$int & 4 ? 'r' : '-', // read | |
$int & 2 ? 'w' : '-', // write | |
$int & 1 ? 'x' : '-' // execute | |
); | |
} |