Skip to content

Instantly share code, notes, and snippets.

@DominikStyp
DominikStyp / User.php
Created February 6, 2024 13:25
PHPStorm: disable error indpection @read-only property beeing assigned for the specified line
<?php
/**
* @property-read int $someProp
* @property int $otherProp
*/
class User {}
@DominikStyp
DominikStyp / User.php
Last active February 1, 2024 13:26
Laravel 10: user custom attributes implementation in User model
<?php
class User extends Authenticatable implements JWTSubject
{
protected function customFields(): Attribute
{
return Attribute::make(
get: fn (?string $value) => (object)json_decode($value),
set: fn (array|object $value) => json_encode($value, JSON_FORCE_OBJECT),
);
@DominikStyp
DominikStyp / User.php
Last active January 23, 2024 16:23
Laravel 10 Model: Use query builder to filter User roles
<?php
declare(strict_types=1);
namespace App\Models;
use App\Models\Passport\Client;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@DominikStyp
DominikStyp / usersImport.sh
Created January 17, 2024 15:20
CURL request in bash: send access_token request, and second request to import users from file
#!/bin/bash
RESPONSE=$(curl --location --insecure --request POST 'http://server.local/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=123' \
--data-urlencode 'client_secret=456' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=123' \
--data-urlencode 'scopes=full_access email openid')
@DominikStyp
DominikStyp / SomeTest.php
Created November 29, 2023 10:30
Mock HTTP Request, and custom facade in Laravel test (PHPUnit)
<?php
namespace Tests\Feature;
use Symfony\Component\HttpFoundation\Request;
use Tests\TestCase;
class BrandResolveByMultipleDomainsTest extends TestCase
{
@DominikStyp
DominikStyp / upgradeLinuxKernel.sh
Last active November 26, 2023 15:13
Upgrade Linux Kernel + Headers:
#!/bin/bash
# first ensure the system is full updated
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
# first search the proper kernel
apt-cache search linux-image
@DominikStyp
DominikStyp / restartWebContainerWithXdebugOff.sh
Last active November 25, 2023 19:58
Laravel Sail + Docker: restart web container with enabled Xdebug
#!/bin/bash
CONTAINER_NAME="web"
echo "Stopping the web container..."
./vendor/bin/sail stop $CONTAINER_NAME
echo "Disabling Xdebug and setting mode to debug,develop..."
./vendor/bin/sail exec $CONTAINER_NAME bash -c "echo 'xdebug.mode=off' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
@DominikStyp
DominikStyp / Dockerfile
Last active November 23, 2023 14:45
Docker: Install xdebug for PHP 7.4
# install xdebug
# xdebug and PHP config in php.ini
RUN pecl install xdebug-3.1.3
RUN docker-php-ext-enable xdebug
@DominikStyp
DominikStyp / Maybe.js
Last active October 15, 2023 17:24
JavaScript monad example
class Maybe {
constructor(v){
this.value = v;
};
bind(func) {
return new Maybe(func(this.value));
}
getValue() {
@DominikStyp
DominikStyp / AppServiceProvider.php
Last active August 17, 2023 15:20
Laravel 10: How to replace the FlySystem FtpAdapter and supress/catch FTP Warnings/Errors
<?php
namespace App\Providers;
use App\Contracts\BrandNameResolverInterface as BrandNameResolverServiceContract;
use App\Http\Controllers\Auth\PasswordBrokerManager;
use App\Repositories\Interfaces\AccountInterface;
use App\Services\Filesystem\FtpAdapter;
use App\Services\User\AccountSessionService;
use App\View\Components\Modal;