Skip to content

Instantly share code, notes, and snippets.

View azjezz's full-sized avatar
😶

Saif Eddin Gmati azjezz

😶
View GitHub Profile
<?php
$array = ['a' => 1 , 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6];
// get the “rest of the values” from an array, when doing destructuring assignment, as a new array.
[$a, $b, ...$others] = $array;
var_dump($a) // int(1)
var_dump($b) // int(2)
@azjezz
azjezz / SessionPersistence.php
Last active October 7, 2018 23:30
PSR-16 based session persistence for zend expressive
<?php
/*──────────────────────────────────────────────────────────────────────────────
─ @author Saif Eddin Gmati <azjezz2@gmail.com>
─────────────────────────────────────────────────────────────────────────────*/
declare(strict_types=1);
namespace Polar\Session;
use DateTime;
use Dflydev\FigCookies\FigResponseCookies;
<?php declare(strict_types=1);
// based on SO answer by Galvic
// https://stackoverflow.com/a/18602474/7427482
function timeago(DateTime $ago, bool $full = false): string {
$now = new DateTime();
$diff = $now->diff($ago);
$values = [
@azjezz
azjezz / factorial.php
Last active December 7, 2018 15:46
PHP Factorial without using a loop
<?php declare(strict_types=1);
/**
* Calculate factorial using recursive function call
*
* @see https://3v4l.org/oeZp9
*
* @param int $n
*
* @throws InvalidArguemntException
@azjezz
azjezz / hell.hh
Created February 2, 2019 15:35
Code that i wish didn't work
<?hh // strict
use namespace HH\Asio;
/**
* Hate both the player, and the game.
*/
<<__EntryPoint>>
async function main(): Awaitable<void> {
@azjezz
azjezz / polyfill.hh
Last active February 11, 2019 23:28
Polyfill for `call_user_func` and `call_user_func_array` in hack lang
<?hh // strict
namespace Polyfill;
use type ReflectionMethod;
use type ReflectionFunction;
function call_user_func(mixed $callable, mixed ...$args): mixed {
return call_user_func_array($callable, $args);
}
require __DIR__.'/vendor/autoload.hack';
use namespace HH\Asio;
use namespace HH\Lib\Str;
use namespace Facebook\TypeAssert;
final class GithubPublicInformation {
const type TFileInfo = shape(
'sha' => string,
'filename' => string,
$baz as Baz -> passed.
$qux as Baz -> failed : Expected Baz, got Qux.
$baz as Qux -> failed : Expected Qux, got Baz.
$qux as Qux -> passed.
$baz as Foo -> passed.
$qux as Foo -> passed.
$baz as Bar -> failed : Expected Bar, got Baz.
$qux as Bar -> passed.
$baz as string -> failed : Expected string, got Baz.
$baz as int -> failed : Expected int, got Baz.
```
use namespace HH\Lib\Vec;
function process(
vec<(string, string, string, string)> $input
): dict<string, dict<string, dict<string, vec<string>>> {
$result = dict[];
foreach($input as $tuple) {
$result[$tuple[0]][$tuple[1]][$tuple[2]] = Vec\concat(
$result[$tuple[0]][$tuple[1]][$tuple[2]] ?? vec[],
@azjezz
azjezz / colors.css
Created May 8, 2019 23:41
Colors used at Polar
/** Colors **/
.primary {
color: #BDC6FF;
}
.secondary {
color: #F4C2C2;
}
.success {
color: #00cec9;