Skip to content

Instantly share code, notes, and snippets.

View ithinkihaveacat's full-sized avatar

Michael Stillwell ithinkihaveacat

View GitHub Profile
<?php
function isStringPresent($needle, $haystack)
{
$result = strstr($haystack, $needle);
if ($result == FALSE) {
return FALSE;
} else {
return TRUE;
}
@ithinkihaveacat
ithinkihaveacat / bench.php
Created November 7, 2011 23:07
Microbenchmarks of different forms of array access
<?php
// Micro-benchmarks, again, see http://daveyshafik.com/archives/30320-faster-arrays.html
// Results:
//
// regular 1.64
// preallocated 1.42
// fixed 0.81
<?php
// From presentation-layer/application/modules/user/models/Givingpage.php
protected function _setIf($givingPage, $data, $key, $field = null)
{
if ($field === null) {
$field = $key;
}
if (isset($data[$key])) {
mycallback({
"count": 10,
"value": {
"title": "test",
"description": "Pipes Output",
"link": "http://pipes.yahoo.com/pipes/pipe.info?_id=bc115235e32da3e0f6db46cd7a159a01",
"pubDate": "Sun, 12 Aug 2012 21:00:39 +0000",
"generator": "http://pipes.yahoo.com/pipes/",
"callback": "mycallback",
"items": [
@ithinkihaveacat
ithinkihaveacat / Vagrantfile.rb
Created September 28, 2012 10:28
Vagrantfile snippet to check that apache_server_name resolves to vm_ip
# Vagrantfile snippet to check that apache_server_name resolves to vm_ip (i.e.
# assuming that the rest of the Vagrantfile configures a VM in this way).
apache_server_name = "myproject.local"
vm_ip = "192.168.33.111"
begin
res = Socket::getaddrinfo(apache_server_name, nil, Socket::AF_INET)
rescue SocketError => e
# s doesn't resolve to anything at all
@ithinkihaveacat
ithinkihaveacat / child-process-event-helper.js
Created February 15, 2013 23:15
Creates event-listener-style communication between parent and child.
function onChild(child, event, callback) {
child.on('message', (function (args) {
if (args[0] === event) {
callback.apply(null, Array.prototype.slice.call(args, 1));
}
}));
}
function emitChild(/* child, event, [arg1], [arg2], [...] */) {
var args = Array.prototype.slice.call(arguments);
<?php
/**
* Similar to print_r(), except that it writes to /tmp/rawlog.log. This function is
* intended for debugging, where you want to be absolutely sure that your output
* is not being captured or buffered or otherwise interfered with.
*
* One good way to ensure this is always available is to use the auto_prepend_file
* php.ini setting.
*/
<?php
array (
0 =>
array (
'file' => '/usr/share/php/BBC/Controller/Plugin/CacheControl.php',
'line' => 59,
'function' => 'rawstack',
),
1 =>
#!/bin/bash
# NOTE: This (sadly) doesn't work in all situations. See
# https://github.com/composer/composer/pull/1083
# for discussion of some alternatives.
# Checks whether composer.json has changed after checkout, in which
# case you probably need to run 'composer install'.
#
# INSTALLATION