Skip to content

Instantly share code, notes, and snippets.

@overnin
overnin / gist:ffd8948d5bd70809c105
Created June 26, 2015 09:26
UrlParam default set
if ($this->Filter->hasConditions($this->Program)) {
$this->params['url'] = array(
'filter_operator' => 'all',
'filter_param' => array(
1 => array(
1 => 'status',
2 => 'is',
3 => 'running'
)
)
<?php
// in the validation rule
....
'content' => array(
'requiredConditional' => array(
'rule' => array('requiredConditionalFieldOrValue', 'type-interaction', 'announcement', 'question-answer', 'question-answer-keyword'),
'message' => 'The interaction required a content.',
),
'notempty' => array(
<?php
//The issue is this function is not easy to test our new behavior we need to refactor it to make it easy to test
protected function _getProgramStats($database)
{
$programStats = array(
'active-participant-count' => 'N/A',
'participant-count' => 'N/A',
'all-received-messages-count'=> 'N/A',
'current-month-received-messages-count' => 'N/A',
function generateHtmlProgramStats(programStats) {
var myTemplate = '<div>'+
'<span ' + ( (programStats!=null) ? 'title="Optin/Totalparticipant(s)"' : 'Stats Not Available') +'class = stat>'+
'ActiveParticipant/TotalParticipantStats'+
'</span> participant(s)'+
'</div>'+
'<div>'+
'<span title = Total(totalcurrentmonth)message(s) class = stat>'+
'Totalhistory(Totalcurrentmonthmessages)'+
'</span> total message(s)'+
@overnin
overnin / CreditManagerComponent.php
Last active December 19, 2015 21:18
How a Test of a Component using redis should look like
<?php
App::uses('Component', 'Controller');
class CreditManagerComponent extends Component{
public $Controller = null;
public $redis = null;
public $redisProgramPrefix = null;
public function initialize(Controller $controller) {
@overnin
overnin / gist:5907845
Last active December 19, 2015 05:59
Example of refactoring to support testing in test database
//in ProgramsController
...
function constructClasses()
{
parent::constructClasses();
$this->_instanciateVumiRabbitMQ();
$this->_instanciateMongoModel("vusion"); //this is hard coded at the moment also so no worry about that
}
@overnin
overnin / gist:5013808
Created February 22, 2013 14:30
i have a problem with validation of something
function formatKeywordValidation(value, element, param) {
var errors = {};
if (isDialogueView()) {
var keywordRegex = new RegExp('^[a-zA-Z0-9]+(,(\\s)?[a-zA-Z0-9]+)*$','i');
} else {
var keywordRegex = new RegExp('^[a-zA-Z0-9\\s]+(,(\\s)?[a-zA-Z0-9\\s]+)*$','i');
}
if (keywordRegex.test(value)) {
return true;
}
@overnin
overnin / gist:3826248
Created October 3, 2012 10:18
Looking for a workaround to install ve for vumi without the problematique riak-pb
Looking for a workaround to install ve for vumi without the problematique riak-pb
## puppet/manifest/vusion.pp (part only)
....
file { "/var/vusion/backend/requirements.py":
ensure => present,
source => "puppet:///config/requirements.pip",
require => [User['supervisordUser'],
Exec['checkout-vusion']],
before => Exec['install-virtualenv']
@overnin
overnin / gist:3225379
Created August 1, 2012 09:21
trial error on vumi transports
My config: Precise32, python 2.7, twisted 12.1.0
(ve)vagrant@precise32:/var/vusion/vusion-backend/ve/src/vumi/vumi$ trial transports/tests/
vumi.transports.tests.test_base
BaseTransportTestCase
test_consumer_registry ... [ERROR]
test_middleware_for_events ... [ERROR]
test_middleware_for_failures ... [ERROR]
test_middleware_for_inbound_messages ... [ERROR]
test_middleware_for_outbound_messages ... [ERROR]
@overnin
overnin / gist:2426748
Created April 20, 2012 07:05
Issue when restarting a Vumi worker
#I get an exception when trying to dynamically restart a worker with the same name.
#In this case the worker is name 'simulator' and has transport_name ='simulator'.
#In the example below, the multiworker has to first stop the worker, then start a new one with the same mane.
#This request as send to the multiworker through control Messages (see in the log "Received control!")
==The Error==
2012-04-20 09:46:27+0300 [WorkerAMQClient,client] 'Unexpected error RuntimeError(u"cannot have two services with same name \'simulator\'",)'
==Logs==