Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / Dockerfile
Created Jan 10, 2023
Tideways PHP Extension on ARM64 Alpine Linux
View Dockerfile
FROM php:8.1-fpm-alpine
ARG TIDEWAYS_EXTENSION_VERSION=5.5.12
ARG TIDEWAYS_PHP_VERSION=8.0
ARG TIDEWAYS_PHP_EXTVER=20200930
RUN wget "https://tideways.s3-eu-west-1.amazonaws.com/extension/${TIDEWAYS_EXTENSION_VERSION}/tideways-php-${TIDEWAYS_EXTENSION_VERSION}-alpine-arm64.tar.gz" && \
tar xvzf tideways-php-${TIDEWAYS_EXTENSION_VERSION}-alpine-arm64.tar.gz && \
cp ./build/dist/tideways-php-alpine-${TIDEWAYS_PHP_VERSION}.so /usr/local/lib/php/extensions/no-debug-non-zts-${TIDEWAYS_PHP_EXTVER}/tideways.so && \
rm -rf tideways-php-${TIDEWAYS_EXTENSION_VERSION}-alpine-arm64.tar.gz ./build
@ziadoz
ziadoz / AppServiceProvider.php
Created Dec 20, 2022
Replace Laravel Artisan Command Output With Custom Implementation
View AppServiceProvider.php
<?php
namespace App\Providers;
use App\YourCustomOutputStyle;
use Illuminate\Console\OutputStyle;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
@ziadoz
ziadoz / refresh_tab.js
Last active Dec 8, 2022
Refresh Browser Tab At Specific Time
View refresh_tab.js
// Resources
// @see: https://www.technipages.com/how-to-auto-refresh-chrome-tabs-without-an-extension
// @see: https://stackoverflow.com/questions/1217929/how-to-automatically-reload-a-web-page-at-a-certain-time
// Paste this into the Web Inspector on the browser tab you want to refresh and hit Enter.
// Change this to the exact time you want to refresh the page at:
let then = new Date('2022-12-09 01:01:00');
window.setTimeout(() => window.location.reload(true), then.getTime() - new Date().getTime());
@ziadoz
ziadoz / mysql8_indexed_json_arrays.sql
Created Dec 8, 2022
MySQL 8 - Search Indexed JSON Arrays
View mysql8_indexed_json_arrays.sql
-- DB Fiddle: https://www.db-fiddle.com/f/3TSbU9ZnpSMkCRgnWYeBep/1
-- Create a customers table with an array JSON column containing their favourite numbers.
create table `customers` (
`id` bigint unsigned auto_increment,
`name` varchar(222),
`numbers` json not null,
primary key (`id`),
key `customers_numbers_index` ((cast(json_extract(`numbers`,_utf8mb4'$[*]') as unsigned array)))
) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_unicode_ci;
@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