Skip to content

Instantly share code, notes, and snippets.

View Saeven's full-sized avatar

Alexandre Lemaire Saeven

View GitHub Profile
@Saeven
Saeven / gist:7308410
Created November 4, 2013 20:03
Using TwigRenderer directly, to render a view script and capture its output
$viewModel = new ViewModel();
$viewModel->setVariables(
array(
'reset_url' => $core->getCurrentSite() . "/reset/" . $reset_hash,
'ip_address' => $core::getIP(),
'promo_name' => $core->getPromotionName(),
)
);
@Saeven
Saeven / gist:7832090
Last active March 31, 2020 03:02
RAW Curl Post to AWS Kinesis with PHP
<?php
/*
POST / HTTP/1.1
Host: kinesis.<region>.<domain>
x-amz-Date: <Date>
Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=content-type;date;host;user-agent;x-amz-date;x-amz-target;x-amzn-requestid, Signature=<Signature>
User-Agent: <UserAgentString>
Content-Type: application/x-amz-json-1.1
Content-Length: <PayloadSizeBytes>
@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 );
@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: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: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 */ );
}
});
$(document).ready( function(){
if( $.cookie('welcome_register') )
{
// show the thanks div
$.removeCookie('welcome_register', { path: '/' });
}
});
@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;
-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);
$("#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' );
});