Skip to content

Instantly share code, notes, and snippets.

@icambridge
icambridge / gist:1799745
Created February 11, 2012 14:24
Monit config file
check system localhost
if memory usage > 65% then exec "/usr/bin/php /root/cloud/create.php"
if memory usage < 20% then exec "/usr/bin/php /root/cloud/terminate.php"
@icambridge
icambridge / rscapi.php
Created February 11, 2012 15:58
Rackspace Cloud Server API PHP Library - modified
<?php
/**
* Rackspace Cloud Server API PHP Library
*
* @package RscApi
*/
/**
* Rackspace Cloud Server API PHP Library
*
@icambridge
icambridge / create.php
Created February 11, 2012 16:01
Rackspace Clould Server creation
<?php
require_once "rscapi.php";
define("API_USER", "");
define("API_KEY", "");
define("LOADBALANCER_ID",5873);
define("FLAVOUR_ID",2);
$rsc = new RscApi(API_USER, API_KEY);
@icambridge
icambridge / terminate.php
Created February 12, 2012 10:59
Rackspace Clould Server termination
<?php
if ('master' == gethostname()) {
exit;
}
require_once "rscapi.php";
define("API_USER", "");
define("API_KEY", "");
define("LOADBALANCER_ID",);
@icambridge
icambridge / Test model
Created February 13, 2012 19:37
Lithium match two input fields
<?php
class Test extends \lithium\data\Model {
public $validates = array(
'field' => array(
array(
'maatch',
'message' => 'The field must match',
'field' => 'field_confirm'
@icambridge
icambridge / Test.php
Created February 25, 2012 14:08
CakePHP model validation assignment
<?php
class Test extends AppModel {
public $validate = array(
'field' => array(
array(
'rule' => array('customRule','Extra argument.'),
'message' => 'The field must validate.'
)
),
@icambridge
icambridge / Test.php
Created February 25, 2012 14:11
Lithium model validation assignment.
<?php
class Test extends \lithium\data\Model {
public $validates = array(
'field' => array(
array(
'customRule',
'message' => 'The field must validate',
'extraOption' => 'Value of the extra option.'
@icambridge
icambridge / Test.php
Created February 25, 2012 14:42
CakePHP model validation match
<?php
class Test extends AppModel {
public $name = 'Test';
public $validate = array(
'field' => array(
array(
'rule' => array('match','field_confirm.'),
'message' => 'The field must match.'
@icambridge
icambridge / ValidatorTest.php
Created February 29, 2012 18:48
Validation unit test
<?php
namespace app\tests\cases\extensions;
use lithium\util\Validator;
class ValidatorTest extends \lithium\test\Unit {
public function testValidationRule() {
$result = Validator::rule('match', 'match', 'any', array('other_field' => 'field', 'values' => array('field' => 'match')));
$this->assertTrue($result);
@icambridge
icambridge / validateChange.php
Created February 29, 2012 18:52
Change the validation rules
<?php
$user = User:create();
// Get the validation rules.
$userModel = new User();
$rules = $userModel->validates;
// Add new
$rules['password']['skipEmpty'] = true;
$rules['confirm_password'] = array(