Skip to content

Instantly share code, notes, and snippets.

View salathe's full-sized avatar
🐮
🔥

Peter Cowburn salathe

🐮
🔥
  • Akamai Technologies
  • Edinburgh, Scotland
View GitHub Profile
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Peter Cowburn</author>
<documentationURL>http://stackoverflow.com/questions/15249380/is-it-possible-to-filter-the-descendant-elements-returned-from-an-xpath-query</documentationURL>
<sampleQuery>select * from {table} where url="http://www.yahoo.com"</sampleQuery>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
<url></url>
<?php
$string = 'example';
var_dump(
empty($string['string_offset']),
isset($string['string_offset']),
$string['string_offset']
);
@salathe
salathe / CallbackJsonSerializer.php
Created January 20, 2013 16:02
Generic JSON serializer using callbacks
<?php
class CallbackJsonSerializer implements JsonSerializable
{
public function __construct($subject, callable $callback)
{
$this->subject = $subject;
$this->callback = $callback;
}
@salathe
salathe / isset.md
Created August 4, 2012 11:32
Crazy shorthand isset() operator.

$var? operator

$var ?           => isset($var)
$var ? default   => isset($var) ? $var : default
$var ?= default  => $var = $var ? default => $var = isset($var) ? $var : default

mixing with existing operators

$var ?? val : default => isset($var) ? val : default

if ($var?) => if (isset($var))

@salathe
salathe / mysql.md
Created July 24, 2012 10:38 — forked from teresko/gist:2907749
cannonical SO comment for mysql_* users
@salathe
salathe / comment.txt
Created June 11, 2012 12:40 — forked from teresko/gist:2907749
cannonical SO comment for mysql_* users
Please, don't use `mysql_*` functions for new code. They are no longer maintained and the community has begun the [deprecation process](http://news.php.net/php.internals/53799). See the [**red box**](http://php.net/mysql-connect)? Instead you should learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide, [this article](http://php.net/mysqlinfo.api.choosing) will help to choose. If you care to learn, [here is good PDO tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers).
/* {{{ proto int count(mixed var [, int mode])
Count the number of elements in a variable (usually an array) */
PHP_FUNCTION(count)
{
zval *array;
long mode = COUNT_NORMAL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &array, &mode) == FAILURE) {
return;
}
@salathe
salathe / example.php
Created April 26, 2012 13:38
New DOM debug output in PHP 5.4.1
<?php
$doc = new DOMDocument();
$doc->loadXML('<example a="b">Test</example>');
$el = $doc->documentElement;
$at = $el->getAttributeNode('a');
$tx = $el->firstChild;
var_dump($doc);
var_dump($el);
<?php
$ul = '<ul id="menu">
<li id="Thing 1" class="some_class">Thing 1</li>
<li id="Thing 2" class="someother_class">Thing 2</li>
<li id="Thing 3" class="some_class">Thing 3</li>
<li id="Thing 4" class="some_class">Thing 4</li>
</ul>';
$dom = new DOMDocument;