Skip to content

Instantly share code, notes, and snippets.

@sasin91
sasin91 / Archive.php
Created September 25, 2018 15:53
Create archives with a pretty fluent syntax
<?php
namespace App;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Storage;
use Phar;
use PharData;
use function is_dir;
use function is_file;
@sasin91
sasin91 / make_windows_usb.sh
Created October 28, 2018 10:26
./make_windows_usb.sh /dev/sdx /storage/Win10_x64.iso
#! /bin/bash
# A very simple, primitive and slightly assuming script for creating a bootable windows 10 USB key.
# First we'll prepare the USB
parted mklabel gpt $1
mkfs.fat32 $11
# Then create the directories...
mkdir -p /mnt/Windows10_source
mkdir -p /mnt/Windows10_target
@sasin91
sasin91 / AutomappingPermissionsTest.php
Last active July 21, 2019 08:59
Auto mapping permissions to policies
<?php
namespace Tests\Unit\Authorization;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class AutomappingPermissionsTest extends TestCase
{
use RefreshDatabase;
<?php
namespace App\Enums;
use App\User;
use BenSampo\Enum\FlaggedEnum;
use function collect;
use function is_object;
final class RBAC extends FlaggedEnum
<?php
namespace App;
use App\Enums\RBAC;
use BenSampo\Enum\Traits\CastsEnums;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
<?php
namespace Tests\Unit;
use App\User;
use App\Enums\RBAC;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
@sasin91
sasin91 / trinitycore.ebuild
Created July 7, 2020 20:43
Ebuild for compiling the latest TrinityCore 3.3.5 on Gentoo
# Copyright 2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
inherit cmake cmake-utils git-r3
DESCRIPTION="TrinityCore WoW Private server for WoTLK 3.3.5a"
HOMEPAGE="https://trinitycore.org"
EGIT_REPO_URI="https://github.com/TrinityCore/TrinityCore.git"
Str::macro('diff', function (string $compare, string $to) {
// First we'll find the determine the bitwise difference between the two strings, using the bitwise XOR operator (^) to compare them.
// Then we'll utilize strspn to determine the position where a difference is found.
$from_start = strspn($compare ^ $to, "\0");
// Next we'll determine the end position, by reversing both strings then utilizing strspn as before.
$from_end = strspn(Str::reverse($compare) ^ Str::reverse($to), "\0");
// here we snip out original value
$value = Str::substr($compare, $from_start, (strlen($compare) - $from_end) - $from_start);
@sasin91
sasin91 / Str.php
Created August 13, 2020 11:52
Str::compare
Str::macro('compare', function (string $value, string $to, string $delimiter = ' ') {
return collect(explode($delimiter, $value))
->zip(explode($delimiter, $to))
->filter(function ($pair) {
return $pair->first() !== $pair->last();
})
->collapse();
});
@sasin91
sasin91 / FormField.component
Last active September 8, 2020 07:55
Infer wired property from slot
<code>
<?php
namespace App\View\Components;
use Illuminate\Support\Str;
use Illuminate\View\Component;
class FormField extends Component
{