Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / MemberOfMacro.php
Created Nov 5, 2021
MySQL 8.0 JSON MEMBER OF Laravel Eloquent Macro
View MemberOfMacro.php
<?php
use Illuminate\Database\Query\Builder;
$memberOf = function ($value, string $column, string $path = '$', $boolean = 'and') {
return $this->whereRaw(
sprintf(
'? MEMBER OF(JSON_EXTRACT(%s, "%s"))',
$this->getGrammar()->wrap($column),
$path
),
@ziadoz
ziadoz / fixchars.sh
Last active Oct 29, 2021
Remove Special Characters From macOS Filenames
View fixchars.sh
#!/usr/bin/env bash
# @see: https://superuser.com/questions/617517/remove-all-illegal-characters-from-all-filenames-in-a-given-folder
# The 's/[\:?\\]//g' regular expression removes ?, : and \ characters.
# Dry Run:
find "/path/to/files" -type f -exec rename -n 's/[\:?\\]//g' {} \;
# Execute:
find "/path/to/files" -type f -exec rename 's/[\:?\\]//g' {} \;
@ziadoz
ziadoz / docker-images-save-and-load.sh
Last active Nov 4, 2021
Bash/ZSH Aliases to Save and Load Docker Images
View docker-images-save-and-load.sh
#!/usr/bin/env bash
function save-docker-images() {
DEST="${1:-.}"
mkdir -p "$DEST"
echo "Saving Docker Images:"
for IMAGE in $(docker images --format "{{.Repository}}"); do
docker save "$IMAGE" > "$DEST/$(echo "$IMAGE" | sed -E 's~:|/~_~g').tar"
@ziadoz
ziadoz / delete-tweets.yml
Last active Mar 16, 2022
Run TwitterDelete using Docker Compose
View delete-tweets.yml
name: Delete Tweets
on:
workflow_dispatch:
schedule:
# Once every month
# @see: https://crontab.guru/#0_0_1_*_*_*
- cron: "0 0 1 * *"
jobs:
delete:
runs-on: ubuntu-latest
@ziadoz
ziadoz / Dockerfile
Created Sep 30, 2021
Docker - PHP, Composer, Google Chrome and ChromeDriver
View Dockerfile
FROM php:8.0-fpm
# Copy Composer:
COPY --from=composer /usr/bin/composer /usr/bin/composer
# Install PHP extensions:
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions zip
@ziadoz
ziadoz / Dockerfile
Last active Jun 30, 2022
Install glibc on PHP Alpine Docker Image
View Dockerfile
FROM php:8-cli-alpine
# @see: @see: https://stackoverflow.com/a/65969295
RUN apk --no-cache add binutils curl \
&& GLIBC_VER=$(curl -s https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest | grep tag_name | cut -d : -f 2 | tr -d \",' ') \
&& curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk \
&& apk add --no-cache \
glibc-${GLIBC_VER}.apk \
@ziadoz
ziadoz / mysql-wait.sh
Created Jul 9, 2021
Wait for MySQL to Start
View mysql-wait.sh
#!/usr/bin/env bash
# Load dot environment file:
export $(cat .env | xargs)
# Wait for MySQL service to start (this could be on the host or in a Docker container):
until mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -e '\q'; do
>&2 echo "MySQL container is unavailable - sleeping"
sleep 1
done
@ziadoz
ziadoz / Toggle Armoury Crate.bat
Created Jul 4, 2021
Toggle ASUS Armoury Crate Service
View Toggle Armoury Crate.bat
SET /P state=Start (1) or Stop (0) Armoury Crate?
@ECHO OFF
IF %state% == 1 (ECHO "Starting Armoury Crate..." & NET START ArmouryCrateControlInterface & NET START ArmouryCrateService) ELSE (ECHO "Stopping Armoury Crate..." & NET STOP ArmouryCrateControlInterface & NET STOP ArmouryCrateService)
ECHO "Done."
PAUSE
@ziadoz
ziadoz / alpinejs-checkboxes.html
Last active Aug 11, 2021
Alpine JS - Checkboxes With All/None Toggle Links
View alpinejs-checkboxes.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="http://unpkg.com/alpinejs" defer></script>
</head>
<body>
<!--
We have to use $refs because x-bind:checked updates the HTML not the prop.
@see: https://github.com/alpinejs/alpine/issues/520
@ziadoz
ziadoz / random-files.sh
Last active Jun 16, 2021
Bash Script to Generate Random Files (small, medium, large)
View random-files.sh
# Generate Random Files
# @see: https://support.google.com/elastifile-support/answer/9899027?hl=en
# Usage: ./random-files.sh -d /path/to/ouput -s 10 -m 20 - l 5
# Large: <2GB
# Medium: <200MB, <8MB each
# Small: <1MB
DEST="$PWD"
SMALL=0
MEDIUM=0