View index.ts
This file contains 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
function getWord(text: string, word: number) { | |
if (word < 1) throw new Error('word must be no less than 1'); | |
const wordIndex = word - 1; | |
// https://regex101.com/r/1zDG8a/2 | |
const words = text.toLowerCase().match(/\w+(?:'\w+)*/g); | |
if (words === null) { | |
throw new Error('Please provide some text'); | |
} |
View error-handler-new.php
This file contains 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 | |
set_error_handler(function (int $errno, string $errstr): bool { | |
if (!(error_reporting() & $errno)) { | |
// Do nothing | |
return false; | |
} | |
echo "Received error with message: $errstr\n"; | |
return true; |
View get-mwf-date.php
This file contains 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 | |
function getNextMwf(DateTime $date): DateInterval | |
{ | |
$m = (clone $date)->modify('next Monday'); | |
$w = (clone $date)->modify('next Wednesday'); | |
$f = (clone $date)->modify('next Friday'); | |
return $date->diff(min($m, $w, $f)); | |
} |
View autocomplete2.php
This file contains 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 | |
require_once 'vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
$request = Request::createFromGlobals(); | |
if (!isset($_ENV['IEX_TOKEN'])) { | |
throw new Exception('IEX token not found.'); |
View autocomplete.php
This file contains 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 | |
require_once 'vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
$request = Request::createFromGlobals(); | |
if (!isset($_ENV['IEX_TOKEN'])) { | |
throw new Exception('IEX token not found.'); |
View YNAB.php
This file contains 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 | |
namespace App\Services; | |
use Symfony\Component\Security\Core\Security; | |
use Doctrine\ORM\EntityManagerInterface; | |
use App\Entity\User; | |
use GuzzleHttp\Client; | |
use GuzzleHttp\RequestOptions; |