Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / s3-presigned-upload-sse.php
Last active Nov 24, 2022
AWS S3 Presigned Upload URL with SSE
View s3-presigned-upload-sse.php
<?php
// The X-Amz-Server-Side-Encryption header must be set in formInputs and options, with the correct case.
new PostObjectV4(
$client,
$bucket,
[
'key' => $key,
'acl' => 'private',
'X-Amz-Server-Side-Encryption' => 'AES256',
],
@ziadoz
ziadoz / awesome-bot.sh
Created Nov 19, 2022
Awesome Bot Docker Command
View awesome-bot.sh
#!/usr/bin/env bash
docker run -ti --rm -v $PWD:/mnt dkhamsing/awesome_bot --allow-dupe --white-list igor.io,symfony,toranproxy.com,vagrantup.com,3v4l.org,voicesoftheelephpant.com,drupal.org,oreilly.com README.md
@ziadoz
ziadoz / LaravelToSlimController.php
Created Oct 27, 2022
Convert Laravel 9 HTTP Requests to Slim 4
View LaravelToSlimController.php
<?php
use Illuminate\Foundation\Application;
use Illuminate\Http\Request as LaravelRequest;
use Illuminate\Http\Response as LaravelResponse;
use Slim\Factory\ServerRequestCreatorFactory;
use Slim\Http\Response as SlimResponse;
use Slim\Http\ServerRequest as SlimServerRequest;
class LaravelToSlimController
{
@ziadoz
ziadoz / ExampleTest.php
Last active Oct 18, 2022
Refresh Database Using Specific Database Connection In Laravel Tests
View ExampleTest.php
<?php
namespace Tests\Feature;
use Tests\RefreshesDatabase;
class ExampleTest
{
use RefreshesDatabase;
public string $connectionToMigrate = 'mysql-elevated';
@ziadoz
ziadoz / token.php
Created Oct 11, 2022
Generate Laravel Password Reset Token For Testing
View token.php
<?php
use Illuminate\Auth\Passwords\PasswordBroker;
$token = app()->get(PasswordBroker::class)->createToken(
User::query()->where('email', '=', 'me@example.com')->first()
);
@ziadoz
ziadoz / .gitattributes
Last active Sep 26, 2022
Prevent Git Managing CSV Line Endings
View .gitattributes
# Prevent Git managing line endings of CSV files, otherwise it changes CRLF to LF on commit and checkout.
# This is useful if you're working with CSV files that come from legacy systems and have differing line endings.
#
# You can see view how Git manages line endings with this command: git ls-files --eol | grep .csv
#
# @see: https://git-scm.com/docs/gitattributes
# @see: https://stackoverflow.com/questions/17628305/windows-git-warning-lf-will-be-replaced-by-crlf-is-that-warning-tail-backwar
# @see: https://stackoverflow.com/questions/42667996/enforce-core-autocrlf-input-through-gitattributes
# @see: https://stackoverflow.com/questions/20496084/git-status-ignore-line-endings-identical-files-windows-linux-environment
# @see: https://stackoverflow.com/questions/21822650/disable-git-eol-conversions
@ziadoz
ziadoz / backup-restore-mysql-docker-volume.sh
Last active Oct 10, 2022
Backup and Restore MySQL Docker Volume
View backup-restore-mysql-docker-volume.sh
#!/usr/bin/env bash
# @see: https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes
# @see: https://jareklipski.medium.com/backup-restore-docker-named-volumes-350397b8e362
# @see: https://www.spherex.dev/backing-up-docker-volumes/
# The name of the volume to backup/restore:
VOLUME="my-db"
# Backup the Docker Volume to an archive:
docker run --rm --volume $VOLUME:/var/lib/mysql -v $(pwd):/backup alpine:latest ash -c "tar cvf /backup/$VOLUME.tar /var/lib/mysql"
@ziadoz
ziadoz / laravel_json_polymorphic_columns.php
Created Jun 29, 2022
Laravel - JSON Polymorphic Columns
View laravel_json_polymorphic_columns.php
<?php
if (! Schema::hasColumns('table', ['model_type', 'model_ids'])) {
Schema::table('table', function (Blueprint $table) {
$table->string('model_type');
$table->json('model_ids');
$table->rawIndex('((CAST(model_ids->"$[*]" AS UNSIGNED ARRAY))), model_type', 'model_ids_model_type');
});
}
@ziadoz
ziadoz / Laravel-Container.md
Last active Jun 27, 2022 — forked from zhilinskiy/Laravel-Container.md
Laravel's Dependency Injection Container in Depth
View Laravel-Container.md

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@ziadoz
ziadoz / human-list.html
Created Apr 7, 2022
CSS Only Human Readable List
View human-list.html
<style>
ul.human-list {
list-style: none;
}
ul.human-list li {
display: inline-block;
}
ul.human-list li:not(:last-child):after {