Skip to content

Instantly share code, notes, and snippets.

View richardDobron's full-sized avatar
💭
🔥 making stuff faster

Richard Dobroň richardDobron

💭
🔥 making stuff faster
View GitHub Profile
<?php
/**
* Use invariant() to assert state which your program assumes to be true.
*
* @throws Exception
*/
function invariant(mixed $condition, string $message = 'Invariant Violation', ...$params): void
{
if (! $condition) {
if (func_num_args() > 2) {
<?php
/**
* A utility that accepts a value and throws an Exception if the value is null,
* otherwise it returns the value.
*
* @throws Exception
*/
function nullthrows(mixed $value, string $message = null): mixed
{
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-door-status-telegram/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
<?php
class User
{
// ...
public function hasRole(int $roleId): bool
{
return $this->roleId === $roleId;
}
<?php
use App\Enums\UserRoleTypes;
class User
{
// ...
public function hasRole(int $roleId): bool
{
<?php
/**
* This file is generated. Do not modify it manually!
*
* This file was generated by:
* php artisan make:enum App\Models\UserRoleTypes --model=UserRole --id=Id --slug=Slug --title=Role
* If there is a newer version, run:
* php artisan make:enum App\Models\UserRoleTypes --model=UserRole --id=Id --slug=Slug --title=Role --force
*/
<?php
$response = new \dobron\BigPipe\AsyncResponse();
$response->setContent('div#content', $newContent);
$response->send();
<?php
$response = new \dobron\BigPipe\AsyncResponse();
$response->reload(250); // reload page with 250ms delay
// or
$response->redirect('/onboarding', 500); // redirect with 500ms delay
$response->send();
<?php
$response = new \dobron\BigPipe\AsyncResponse();
$response->setPayload([
'username' => $_POST['username'],
'status' => 'unavailable',
'message' => 'Username is unavailable.',
]);
$response->send();
<?php
$asyncResponse = new \dobron\BigPipe\AsyncResponse();
// $asyncResponse->bigPipe()->require(["SecretModule", "run"], ... )
// is same as:
$asyncResponse->bigPipe()->require("require('SecretModule').run()", [
'first argument',
'second argument',
// ...
]);
$asyncResponse->send();