Skip to content

Instantly share code, notes, and snippets.

@borisguery
borisguery / wssetoken.php
Created September 27, 2012 08:19
WsseToken generator for curl
#!/usr/bin/env php
<?php
function wsse_header($username, $password) {
$nonce = hash_hmac('sha512', uniqid(null, true), uniqid(), true);
$created = new DateTime('now', new DateTimezone('UTC'));
$created = $created->format(DateTime::ISO8601);
$digest = sha1($nonce.$created.$password, true);
return sprintf(
@borisguery
borisguery / directorySplit.php
Created September 25, 2012 15:28
Split a directory into sub-directories
<?php
function directorySplit($dir, $segmentSize = 2, $maxSegment = 3, $dirSeparator = DIRECTORY_SEPARATOR)
{
$segmentedDir = '';
for ($i = 0, $segmentOffset = 0; $i < $maxSegment && strlen($dir) > $segmentOffset; ++$i, $segmentOffset = $segmentSize * $i) {
$segment = substr($dir, $segmentOffset, $segmentSize) . $dirSeparator;
if (strlen($segment) < $segmentSize) {
break;
}
@borisguery
borisguery / version2integer.php
Created September 21, 2012 08:45
Version to Integer
<?php
function version2integer($version) {
$matches = array();
preg_match('/([0-9.]+)/', $version, $matches);
if (count($matches) > 1) {
$maxSequences = 4; // v12.34.56.78.90 will stop at 78
$matches = explode('.', $matches[1]);
$matches = $matches + array(0, 0, 0, 0);
@borisguery
borisguery / gist:3134871
Created July 18, 2012 07:43
SplFixedArray vs Native Array lookup performance
<?php
ini_set('memory_limit', -1);
$count = (int)$argv[1];
function fixed_array_search_foreach($stack, $counter, $lookup, $type) {
$start = microtime(true);
foreach ($stack as $key => $value) {
if ($lookup === $value) {