Skip to content

Instantly share code, notes, and snippets.

View jamiehannaford's full-sized avatar

Jamie Hannaford jamiehannaford

View GitHub Profile
@jamiehannaford
jamiehannaford / switch.sh
Created September 6, 2013 12:32
The convention for Go working environments is to clump everything in one "Gopath" - which kind of acts as a universal environment. But I don't like that; if I'm working on multiple Git projects, I might want a completely separate environment with separate packages and a src directory just for my project. Maybe I'm wrong but this seems to work. N…
#!/bin/bash
subdir=${1%/}
if [ ! $subdir ]; then
echo "Please specify an argument"
exit
fi
dir="${PWD}/$subdir"
@jamiehannaford
jamiehannaford / gist:6544206
Created September 12, 2013 21:39
PHP test
<?php
class TestA {
public $foo = 'bar';
}
$class = new TestA();
var_dump((array) $class);
@jamiehannaford
jamiehannaford / minify_json.py
Last active December 28, 2015 02:59
check a project folder for dodgy JSON files and then minify
import os
import sys
import json
rootdir = sys.argv[1]
for root, subFolders, files in os.walk(rootdir):
for file in files:
if (os.path.splitext(file)[1] == '.json'):
path = os.path.join(root,file)
with open(path,'r') as f:
public function uploadObjects(array $files, array $commonHeaders = array())
{
$requests = $entities = array();
foreach ($files as $entity) {
if (empty($entity['name'])) {
throw new Exceptions\InvalidArgumentError('You must provide a name.');
}
@jamiehannaford
jamiehannaford / node.php
Created December 13, 2013 12:24
Change the condition of a LB Node
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, [
'username' => 'foo',
'apiKey' => 'bar'
]);
$service = $client->loadBalancerService();
$loadBalancer = $service->loadBalancer('<lb_id>');
@jamiehannaford
jamiehannaford / composer.json
Created December 13, 2013 12:28
Force Composer to pull a specific commit
"require": {
"rackspace/php-opencloud": "dev-master:d81c8cfff72612f71dccff1e0a03dfe8be874a4c"
}
@jamiehannaford
jamiehannaford / add_backoff.php
Last active January 3, 2016 07:59
add guzzle backoff strategy to client object
<?php
// First make sure you have the BackoffPlugin installed:
// $ composer require guzzle/guzzle
use Guzzle\Plugin\Backoff\BackoffPlugin;
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => 'foo',
@jamiehannaford
jamiehannaford / cache_token.php
Created January 15, 2014 09:01
cache token to bypass future auth requests
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => 'foo',
'apiKey' => 'bar'
));
$cacheFile = __DIR__ . '/.opencloudToken';
$token = $client->getTokenObject();
@jamiehannaford
jamiehannaford / enable_logging.php
Last active January 3, 2016 13:29
enable logging
<?php
use Guzzle\Plugin\Log\LogPlugin;
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => 'foo',
'apiKey' => 'bar'
));
@jamiehannaford
jamiehannaford / hp_service.php
Last active January 4, 2016 16:49
override service class for HP services
use Guzzle\Http\ClientInterface;
use OpenCloud\Common\Service\CatalogService;
class HpService extends CatalogService
{
public function __construct(ClientInterface $client, $type = null, $region = null, $urlType = null)
{
$this->setClient($client);
$this->region = $region;