This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Storage { | |
static get(key) { | |
let value = localStorage.getItem(key); | |
return value === null ? null : JSON.parse(value); | |
} | |
static set(key,value) { | |
return localStorage.setItem(key,JSON.stringify(value)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
/** | |
* Calculate factorial using recursive function call | |
* | |
* @see https://3v4l.org/oeZp9 | |
* | |
* @param int $n | |
* | |
* @throws InvalidArguemntException |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*────────────────────────────────────────────────────────────────────────────── | |
─ @author Saif Eddin Gmati <[email protected]> | |
─────────────────────────────────────────────────────────────────────────────*/ | |
declare(strict_types=1); | |
namespace Polar\Session; | |
use DateTime; | |
use Dflydev\FigCookies\FigResponseCookies; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh // strict | |
use namespace HH\Asio; | |
/** | |
* Hate both the player, and the game. | |
*/ | |
<<__EntryPoint>> | |
async function main(): Awaitable<void> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
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[], |
OlderNewer