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
string(7) "Example"
object(Example)#1 (0) {
}
Fatal error: Call to private Example::__construct() from invalid context in <file> on line 18
-- 5.1.0 --
string(3) "n/a"
bool(false)
string(3) "n/a"
bool(true)
string(3) "n/a"
bool(false)
-- 5.1.1 --
@salathe
salathe / results.txt
Created January 24, 2012 20:55
PHP array/string functions haystack/needle ordering
Array functions:
array_search $needle, $haystack
in_array $needle, $haystack
String functions:
strchr $haystack, $needle
stripos $haystack, $needle
stristr $haystack, $needle
strpos $haystack, $needle
strrchr $haystack, $needle
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="0"
yahoo:created="2012-04-10T10:46:17Z" yahoo:lang="en-US">
<diagnostics>
<publiclyCallable>true</publiclyCallable>
<redirect from="http://www.google.com/ig/api?weather=CM12QE" status="302">
<![CDATA[http://www.google.com/sorry/?continue=http://www.google.com/ig/api%3Fweather%3DCM12QE]]>
</redirect>
<url execution-start-time="4" execution-stop-time="2198" execution-time="2194"
http-status-code="503" http-status-message="Service Unavailable"
@salathe
salathe / timeZone.c
Created April 17, 2012 19:57
GeoIP_time_zone_by_country_and_region from http://www.maxmind.com/app/c
#include <string.h>
const char* GeoIP_time_zone_by_country_and_region(const char * country,const char * region) {
const char* timezone = NULL;
if (country == NULL) {
return NULL;
}
if (region == NULL) {
region = "";
}
if ( strcmp (country, "AD") == 0 ) {
<?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;
@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);
/* {{{ 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 / 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).