Skip to content

Instantly share code, notes, and snippets.

@Gisleburt
Gisleburt / getInvalidProperties.php
Last active August 29, 2015 14:01
Checks each property (eg $property_name) of an object for a validatePropertyName($value) function, and runs it. If it's invalid it adds it to an array of invalid properties and returns it.
<?php
class SomeClass {
const FIELD_MISSING = 'Missing';
const FIELD_INVALID = 'Invalid';
/**
* Checks each field for a validate function for each field of the object and runs it
* Override to change this functionality
@Gisleburt
Gisleburt / SecurityChecks.sh
Last active August 29, 2015 14:01
Just a few basic security checks to speed up an audit I'm running through.
#!/bin/bash
cat /etc/*release
grep 'PermitRootLogin\|PasswordAuthentication' /etc/ssh/sshd_config
sudo /etc/init.d/denyhosts status
sudo /etc/init.d/fail2ban status
sudo grep '/home' /etc/passwd | cut -d : -f 1 | awk '{ sudo system("sudo passwd -S " $0) }' | grep -C 9999 ' P \| set\,' --color
echo "select Host, User, Password from mysql.user; select ''; show variables like 'version';" | mysql -uroot -p
/usr/sbin/apachectl -v
php -v
/*
An alternative implementation that avoids the horrifying syntax of
prototype. Prototype has it's advantages so if you want the original
it's here: https://gist.github.com/banksean/300494
Changes:
* Changed to YUI Object Pattern
* Simplified code
ToDo:
@Gisleburt
Gisleburt / php-server.sh
Created September 16, 2014 23:48
Start / Stop the PHP server (using router.php) in the background
#!/bin/bash
if [ -e "server.pid" ]
then
echo Stopping server
kill `cat server.pid`
rm server.pid
cat error.log
else
echo Starting server
php -S localhost:8000 router.php >> server.log 2> error.log &
@Gisleburt
Gisleburt / Cache.php
Created September 17, 2014 09:37
An extremely simple key/value file cache for PHP
class Cache {
/**
* The name of the cache file
* @var string
*/
protected $cacheFile;
/**
* The cache data
@Gisleburt
Gisleburt / phanntomjs-driver.sh
Last active August 29, 2015 14:07
Starts / stops phantomjs webdriver on port 4444
#!/bin/bash
dir=$(pwd)
mkdir ~/phantomjs 2> /dev/null
cd ~/phantomjs
if [ -e "phantomjs.pid" ]
then
echo Stopping webdriver
@Gisleburt
Gisleburt / FeatureContext.php
Created April 14, 2015 09:08
A possible method of E2E testing Aye Aye Api
<?php
namespace AyeAye\Tests\Behat;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Guzzle\Http\Client;

Keybase proof

I hereby claim:

  • I am Gisleburt on github.
  • I am gisleburt (https://keybase.io/gisleburt) on keybase.
  • I have a public key whose fingerprint is 708F DF23 13E1 F651 A167 CB81 1E51 9AC2 539B 8E7E

To claim this, I am signing this object:

@Gisleburt
Gisleburt / CloudFormationTemplateValidator.php
Last active August 29, 2015 14:24
AWS Cloud Formation Precommit Validation
<?php
/**
* Class CloudFormationTemplateValidator
* @example
* echo 'Validating Cloud Formation Templates'.PHP_EOL;
* $hook = new CloudFormationTemplateValidator();
* $files = array_slice($argv, 1); // Get a list of files from arguments
* $files = $files ?: $hook->getFilesRecursively('/^.+\.json$/i', getcwd()); // ...or recursively from the working dir
* if(!$hook->validateCloudFormationTemplates($files)) {
@Gisleburt
Gisleburt / TestCase.php
Created October 21, 2015 15:32
Adding a method to PhpUnits TestCase to get any method from another class and return a closure that will call it with the provided arguments
<?php
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
/**
* Gets returns a proxy for any method of an object, regardless of scope
* @param object $object Any object
* @param string $methodName The name of the method you want to proxy
* @return \Closure