Skip to content

Instantly share code, notes, and snippets.

View enygma's full-sized avatar

Chris Cornutt enygma

View GitHub Profile
@enygma
enygma / gist:1245075
Created September 27, 2011 13:45
Getting the raw graph data for a SoftLayer server
<?php
/**
* Pull the bandwidth data from the API by server's tracking object ID
*
*/
$soapClient = SoftLayer_Controller_Action_Helper_SoapClient::getSoapClient('SoftLayer_Hardware_Server', $deviceId);
$objectMask = new SoftLayer_Soap_ObjectMask();
$objectMask->metricTrackingObject;
@enygma
enygma / gist:1245080
Created September 27, 2011 13:48
Pull the bandwidth graph data for a server
<?php
/**
* Pull the bandwidth graph data from the SoftLayer API via a custom graph config object
*
*/
$metrics = array();
$metric = new SoftLayer_Container_Metric_Data_Type(null);
$metric->name = 'url_uptime';
$metric->summaryType = 'publicIn';
@enygma
enygma / gist:1413370
Created December 1, 2011 03:45
Simple RSS feed creation for @PHPQuickFix
<?php
$jsonCacheFile = './quickfix.json';
$gimmieFeed = 'https://gimmebar.com/api/v0/public/assets/phpquickfix';
$wgetCmd = 'wget -O'.$jsonCacheFile.' '.$gimmieFeed;
// look for the cache file
if(!is_file($jsonCacheFile) || (is_file($jsonCacheFile) && filemtime($jsonCacheFile)<strtotime('-1 minute')) ){
// fetch the latest content from gimmiebar
exec($wgetCmd);
@enygma
enygma / gist:2205447
Created March 26, 2012 14:24
RESTful testing with Behat
Feature: Testing the RESTfulness of the Index controller
Let's see how RESTish this is
Scenario: Creating a new User
Given that I want to make a new "User"
And that the its "name" is "Chris"
And I request "/user/index.json"
And the response is JSON
And the response has a "userId" property
And the type of the "userId" property is numeric
@enygma
enygma / gist:2697434
Created May 14, 2012 21:41
Hashing in REST Requests (with FuelPHP)
<?php
class Controller_User extends Controller_Rest
{
protected function validateHash()
{
$request = file_get_contents('php://input');
$requestHeaders = apache_request_headers();
if (!isset($requestHeaders['X-Auth']) || !isset($requestHeaders['X-Auth-Hash'])) {
$this->response('fail!',401);
{
"require": {
"behat/behat": ">=2.2.2",
"behat/mink" : ">=1.3.2",
"guzzle/guzzle": ">=2.0.1",
"fabpot/goutte": "*",
"behat/sahi-client": "*",
"alexandresalome/php-selenium": "*",
"facebook/php-webdriver": "*"
},
<?php
// autoload_namespace.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname(dirname($vendorDir));
return array(
'Zend\\Validator' => $vendorDir . '/zendframework/zend-validator/php/',
'Zend\\Uri' => $vendorDir . '/zendframework/zend-uri/php/',
[Behat\Behat\Exception\ErrorException]
Exception has been thrown in "beforeSuite" hook, defined in FeatureContext::initMinkSessions()
@enygma
enygma / gist:3494587
Created August 28, 2012 03:09
checking entities in XMLReader
<?php
$r = new XMLReader();
$r->xml($post);
while ($r->read()) {
if ($r->nodeType == 10) {
$doc = $r->readOuterXML();
// see if we have any entities
preg_match_all('#<!ENTITY (.*?)>#ims',$doc,$matches);
if (!empty($matches[1])) {
@enygma
enygma / gist:3906604
Created October 17, 2012 16:37
Change in Guzzle options for CURL and self-signed certs
<?php
/**
* When using Guzzle with self-signed certs, something recently changed that makes the
* previous manual config no longer work...see below
*/
// this no longer works
$init = array(
'curl.CURLOPT_SSL_VERIFYHOST' => false,
'curl.CURLOPT_SSL_VERIFYPEER' => false,