Skip to content

Instantly share code, notes, and snippets.

View nyamsprod's full-sized avatar
😴

ignace nyamagana butera nyamsprod

😴
View GitHub Profile
@nyamsprod
nyamsprod / stream_filter.php
Last active August 29, 2015 13:58
Using League\Csv with stream filter
<?php
stream_filter_register("utf8encode", "Utf8EncodeFilter");
class Utf8EncodeFilter extends php_user_filter
{
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = utf8_encode($bucket->data);
$consumed += $bucket->datalen;
@nyamsprod
nyamsprod / benchmark.php
Last active August 29, 2015 14:04
A simple benchmark to use League\Csv
<?php
use League\Csv\Writer;
require 'vendor/autoload.php';
function generateRandomString($length = 10)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str = '';
@nyamsprod
nyamsprod / getrelativepath.php
Created July 25, 2014 08:57
get a relative path from another path
<?php
header('Content-Type: text/html; charset=utf-8');
function getRelativePath($path, $reference)
{
//normalisation des parametres
$path = (string) $path;
if ('/' == $path[0]) {
$path = substr($path, 1);
@nyamsprod
nyamsprod / CacheItem.php
Last active August 29, 2015 14:04
CacheItemInterface::setExpiration improved
<?php
namespace CacheLib;
use DateTime;
use DateTimeInterface;
use DateTimeInterval;
use Psr\Cache\CacheItemInterface
class CacheItem implements CacheItemInterface
@nyamsprod
nyamsprod / new-league-csv-benchmark.php
Created January 28, 2015 14:09
Benchmark for league Csv 6.4+
use League\Csv\Writer;
function generateRawData($start, $end)
{
for ($i = $start; $i < $end; $i++) {
$index = $i;
yield [
'cell--'.($index),
'cell--'.($index+1),
'cell--'.($index+2),
@nyamsprod
nyamsprod / filtering-pdostatement.php
Last active August 29, 2015 14:26
Filtering a Traversable object using PHP SPL filtering capabilities in response to http://www.dragonbe.com/2015/07/speeding-up-database-calls-with-pdo-and.html
<?php
$pdo = new \PDO(
$config['db']['dsn'],
$config['db']['username'],
$config['db']['password']
);
$sql = 'SELECT * FROM `gen_contact` ORDER BY `contact_modified` DESC';
$stmt = $pdo->prepare($sql);
@nyamsprod
nyamsprod / dabblet.css
Created September 10, 2012 19:45
Re-creating Bref style with CSS3 animation
/* Re-creating Bref style with CSS3 animation */
html, body { margin:0 auto; padding:0; color:#fff; background-color:#444; font-size:18px; line-height:1.5; font-family:Trocchi, Serif; text-align:center; }
body { padding-top:100px; }
a { color:rgb(252, 96, 0); transition:all .3s linear; }
a:hover { color:rgb(232, 199, 69); }
ul { margin:0 auto; padding:0; list-style:none; clear:both; overflow:hidden; width:100%; }
.wrapper { margin:0 auto 40px; width:400px; padding:0; position:relative; transform:scale(2); }
@nyamsprod
nyamsprod / final-regexp.php
Last active November 7, 2015 13:49
RegularExpressionDocumented.php
<?php
$uri = 'http://www.ics.uci.edu/pub/ietf/uri/#Related';
$regexp = ',^
((?<scheme>[^:/?\#]+):)? # URI scheme component
(?<authority>//([^/?\#]*))? # URI authority part
(?<path>[^?\#]*) # URI path component
(?<query>\?([^\#]*))? # URI query component
(?<fragment>\#(.*))? # URI fragment component
,x';
@nyamsprod
nyamsprod / dabblet.css
Created January 4, 2013 10:46
Gradient Progress bar
/**
* Gradient Progress bar
*/
html, body { background-color:#fff; color:#222; text-align:center; }
[class^=loading-] { box-sizing:border-box; margin:1em auto; width:300px; height:20px; }
.loading-outer { overflow:hidden; border-radius:.3em; background-color:#f1f1f1; box-shadow:inset 0 0 2px rgba(128, 128, 128, .3); }
.loading-inner {
margin-top:0; margin-left:100%;
background-color:#0ebdf7;
background-image:linear-gradient(45deg, rgba(255, 255, 255, .2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, .2) 75%, transparent 75%);
@nyamsprod
nyamsprod / dabblet.css
Created January 6, 2013 19:40
The Kitt Effect using Efficient CSS Animation
/**
* The Kitt Effect using Efficient CSS Animation
*/
html, body {
font:normal 100%/1.5 sans-serif;
}
.kitt,
.kitt div,