Skip to content

Instantly share code, notes, and snippets.

View kanian's full-sized avatar

Patrick Adou kanian

  • Abidjan, Ivory Coast
View GitHub Profile
@kanian
kanian / BackgroundSlider.css
Created April 7, 2016 11:12
Full Background Slider
.background-slider {
position: absolute;
top:0;
left:0;
z-index: -1;
height:100%;
width:100%;
background-size: cover;
background-position: center;
}
@kanian
kanian / fiddle.css
Created April 7, 2016 11:34
BGSlider Fiddle
.background-slider {
position: absolute;
top:0;
left:0;
z-index: -1;
height:100%;
width:100%;
background-size: cover;
background-position: center;
}
@kanian
kanian / kLeftArrayRotation
Last active September 10, 2017 13:02
k-Left rotation on array of size n
function shiftArray(n,k,a){
var remainingAfterLeftShifts = (n - k) > 0 ? n - k : k - n;
var tailStartIndex = n - remainingAfterLeftShifts;
var tail = a.slice(tailStartIndex, n);
var head = a.slice(0, tailStartIndex);
var shifted = tail.concat(head);
return shifted.join().replace(/,/g," ");
}
<?php
function singletonize(\Closure $func)
{
$singled = new class($func)
{
// Hold the class instance.
private static $instance = null;
public function __construct($func = null)
{
if (self::$instance === null) {
<?php
class ClassThatMarksDateOfInstantiation
{
private $dob;
public function __construct()
{
$this->dob = new \DateTimeImmutable;
}
public function getDob()
{
@kanian
kanian / pattern_proxynode_visitor.php
Created March 19, 2019 18:44
A PHP Parser node visitor
<?php
namespace Assoa\Parser;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Assoa\Commands\BuilderCommand;
use PhpParser\NodeVisitorAbstract;
use Assoa\Parser\INodeVisitorFactory;
use PhpParser\Node\Stmt\ClassMethod;
@kanian
kanian / Proxy.php
Last active March 20, 2019 16:55
Builds a Proxy to a Subject Class
<?php
namespace Assoa\Patterns\Proxy;
use Assoa\Parser\INodeVisitorFactory;
use Assoa\Parser\ProxyNodeVisitorFactory;
use Assoa\Patterns\IPattern;
use Assoa\Patterns\Pattern;
use InvalidArgumentException;
use PhpParser\NodeTraverser;
use PhpParser\Node\Expr\Assign;
@kanian
kanian / Yo.php
Created March 19, 2019 19:20
A dummy class
<?php
class Yo{
public $yo;
public function __construct(){
echo $this->yo;
}
public function hein(string $what){
$this->yo = $what;
}
<?php
require "./vendor/autoload.php";
use Assoa\Yo\Yo;
use Assoa\Loader\Loader;
use PhpParser\NodeDumper;
use Assoa\PatternFactories\ProxyFactory;
Loader::setLoader(require ("./vendor/autoload.php"));
@kanian
kanian / Proxy_example_generated.php
Last active March 20, 2019 17:53
Proxy Generated
<?php
namespace Assoa\Yo;
class Yo_Proxy_02e38a51_a0bc_4c1a_b9ee_77a6fceea0da extends Yo
{
function __construct()
{
$args = func_get_args();
$this->{'subjectInstance'} = new Yo(...$args);