Skip to content

Instantly share code, notes, and snippets.

View Saeven's full-sized avatar

Alexandre Lemaire Saeven

View GitHub Profile
@Saeven
Saeven / ZF 2.4 PHPUnit Bootstrap
Created April 6, 2015 21:27
Lets you use your application config as though you were in-app.
<?php
namespace ApplicationTest;
use Zend\Loader\AutoloaderFactory;
use Zend\Mvc\Service\ServiceManagerConfig;
use Zend\ServiceManager\ServiceManager;
use RuntimeException;
error_reporting(E_ALL | E_STRICT);
@Saeven
Saeven / gist:da7a1a085da381589401
Created October 24, 2014 14:28
Dynamically Substitute template in ZF2
$eventManager->attach( MvcEvent::EVENT_DISPATCH, function( MvcEvent $e ){
$route_name = 'something';
$new_template = 'something-else';
if( $e->getRouteMatch() && $e->getRouteMatch()->getMatchedRouteName() == $route_name )
$e->getViewModel()->setTemplate( $new_template );
});
$("#sort").on('change', function( e ){
var sort = $(this).val();
$("div#collage").empty();
$("div#collage").spin('show');
$.get( '/redeem/sweeps/sort', { 'sort': sort }, function( data ){
$("div#collage").html( data );
Ladda.bind( 'button.ladda-button' );
});
-webkit-box-shadow: 0px 0px 15px 3px rgba(50, 50, 50, 0.8);
-moz-box-shadow: 0px 0px 15px 3px rgba(50, 50, 50, 0.8);
box-shadow: 0px 0px 15px 3px rgba(50, 50, 50, 0.8);
@Saeven
Saeven / gist:c953630d37ed57028c85
Created July 21, 2014 19:22
PHP DynamoDB Poll using Zend Framework 2
<?php
namespace Application\Controller;
use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Enum\ComparisonOperator;
use Aws\DynamoDb\Enum\Type;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
$(document).ready( function(){
if( $.cookie('welcome_register') )
{
// show the thanks div
$.removeCookie('welcome_register', { path: '/' });
}
});
@Saeven
Saeven / gist:bb5a95c27afbc186cdb8
Created May 23, 2014 13:52
Possible to switch a route?
$sem->attach('Zend\Mvc\Application', MvcEvent::EVENT_ROUTE, function( MvcEvent $ev) use($sm,$em) {
$rm = $ev->getRouteMatch()->getMatchedRouteName();
if( getenv("environment") === "master" && $rm == 'zfcuser' )
{
$ev->setRouteMatch( /* switch the route out here */ );
}
});
@Saeven
Saeven / gist:9740815
Created March 24, 2014 14:10
Where oh where does the break_chain_on_failure go?
$recaptcha = new Captcha\ReCaptcha();
$recaptcha
->setOption( 'theme', $theme )
->setPubKey( '6Ld-&amp;hl='.$lang)
->setPrivKey( '6Ld-' )
->setMessage( _( "Correctly repeat the text in the image, in the box beneath it" ) );
$captcha = new Element\Captcha( 'captcha' );
$captcha
@Saeven
Saeven / gist:8651055
Created January 27, 2014 15:51
Subquery in ZF2 in AbstractTableGateway implementation
public function fetchAllWithVotes()
{
$resultset = $this->select( function( Select $select ){
$sub = new Select( 'votes' );
$sub->columns( array( 'total' => new Expression('COUNT(*)') ) )
->where( 'songs.id = votes.song_id' );
$select->columns(
array(
@Saeven
Saeven / gist:8318339
Created January 8, 2014 15:18
Regex vs Filter/Count/Ctype
<?php
set_time_limit( 0 );
$searchText = 'Page and Brin originally nicknamed THEIR new search engine "BackRub", because the system checked backlinks to estimate the importance of a site.';
$start = microtime_float();
for( $i = 0 ; $i < 1000000 ; $i++ )
{
preg_match_all("/[A-Z]{1}[a-zA-z]*/", $searchText, $matches );