Skip to content

Instantly share code, notes, and snippets.

@jadell
jadell / gist:1491837
Created December 17, 2011 23:49
Decode JSON in bach with PHP
alias json-decode="php -r 'print_r(json_decode(file_get_contents(\"php://stdin\")));'"
@jadell
jadell / invoker.php
Created January 14, 2012 03:36
Command invoker pattern
<?php
interface Command
{
public static function register();
public function execute();
}
class HelloCommand implements Command {
protected $name;
@jadell
jadell / mutual.php
Created January 25, 2012 02:14
Mutual friends with Cypher
<?php
$client = new Everyman\Neo4j\Client();
$queryString =
"START firstPerson=node({firstId}), secondPerson=node({secondId}) " .
"MATCH firstPerson -[:FRIEND]-> mutualFriend <-[:FRIEND]- secondPerson" .
"RETURN mutualFriend";
$params = array(
"firstId" => 123,
@jadell
jadell / sudoredirect.sh
Created March 30, 2012 15:19
sudo redirect output
sudo sh -c 'ls -hal /root/ > /root/test.out'
@jadell
jadell / cypher_delete.php
Created November 11, 2012 01:26
Delete nodes using a cypher query in neo4jphp
<?php
error_reporting(-1);
ini_set('display_errors', 1);
spl_autoload_register(function ($sClass) {
$sLibPath = __DIR__.'/../lib/';
$sClassFile = str_replace('\\',DIRECTORY_SEPARATOR,$sClass).'.php';
$sClassPath = $sLibPath.$sClassFile;
if (file_exists($sClassPath)) {
require($sClassPath);
}
@jadell
jadell / 0-initial.php
Created November 21, 2012 01:54
DI migration examples
<?php
// index.php
$app->get('/{id}', function ($id) use ($app) {
$controller = new Lal\HelloController();
return $controller->helloId($id);
});
$app->get('/', function () use ($app) {
$controller = new Lal\HelloController();
return $controller->index();
});
@jadell
jadell / loggly_api.js
Created April 13, 2013 03:50
Ajax query of Loggly from jQuery
$.ajax("https://mydomain.loggly.com/api/facets/date/?q=my_search_criteria", {
// Don't send the _=timestamp query parameter
cache: true,
// Send HTTP auth credentials
username: api_readonly_username,
password: api_readonly_password,
// Use JSONP
dataType: "jsonp"
}).done(function(data) {
// handle data, probably a call to some graphing library
@jadell
jadell / manifests-site.pp
Last active December 16, 2015 13:19
Puppet manifests and templates for configuring an instance to talk to Loggly
class base_node {
loggly::device { "application_log": }
loggly::device { "apache_access": }
loggly::device { "apache_error": }
}
@jadell
jadell / session_serialize.php
Last active June 21, 2018 01:29
Serialize PHP data like a PHP session
<?php
function session_serialize(array $data) {
$temp = $_SESSION;
$_SESSION = $data;
$out = session_encode();
$_SESSION = $temp;
return $out;
}
function session_unserialize($data) {
@jadell
jadell / benchmark.php
Created October 25, 2013 23:23
Performance benchmarks of neo4jphp streaming header vs. no streaming header, using curl and file stream transports
<?php
use Everyman\Neo4j\Client,
Everyman\Neo4j\Transport\Stream,
Everyman\Neo4j\Transport\Curl,
Everyman\Neo4j\Cypher\Query;
require_once 'example_bootstrap.php';
$transport = new Stream();
// $transport = new Curl();