Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / Dockerfile
Created Jul 9, 2021
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,3 | 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
@ziadoz
ziadoz / resize-llm-volume.sh
Last active Jun 8, 2021
Laravel Homestead - Increase LLM Volume Size
View resize-llm-volume.sh
#!/usr/bin/env bash
# @see: https://chasingcode.dev/blog/fix-vagrant-homestead-cant-create-database/
# @see: https://github.com/laravel/homestead/issues/1189#issuecomment-787935903
# @see: https://laracasts.com/discuss/channels/guides/a-guide-to-extending-homestead-storage-capacity
# @see: https://www.thegeekdiary.com/how-to-enable-thin-lvm-automatic-extension/
# @see: https://laracasts.com/discuss/channels/guides/a-guide-to-extending-homestead-storage-capacity
# @see: https://askubuntu.com/questions/433705/dev-mapper-ubuntu-vg-root-is-full
# Default LVM volume size is 64GB, this will add 50% of the available disk space (512GB) to it, making it 256GB:
@ziadoz
ziadoz / extract-vmdk.sh
Last active Jun 4, 2021
Extract VMDK Disk Image on macOS
View extract-vmdk.sh
#!/usr/bin/env bash
# Unzip Vagrant .box file:
tar -xf <box> -C <destination>
# Install 7 Zip:
brew install p7zip
# Extract VMDK:
7z x -y -o<destination> <vmdk>
@ziadoz
ziadoz / php80_attributes.php
Last active Jun 18, 2021
Using PHP 8.0 Attributes/Annotations To Decorate Functions
View php80_attributes.php
<?php
// Attributes (AKA Annotations).
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_FUNCTION)]
class CharDecoratorAttribute
{
public function __construct(protected string $char) // Constructor Property Promotion
{
}
public function decorate(Closure $fn): Closure
@ziadoz
ziadoz / php8.0-install.sh
Last active Dec 4, 2020
Quick PHP 8.0 Install - Ubuntu 18.04
View php8.0-install.sh
#!/usr/bin/env bash
LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y \
php8.0 php8.0-bcmath php8.0-bz2 php8.0-cgi php8.0-cli php8.0-common php8.0-curl php8.0-dba php8.0-dev \
php8.0-enchant php8.0-fpm php8.0-gd php8.0-gmp php8.0-imap php8.0-interbase php8.0-intl php8.0-ldap \
php8.0-mbstring php8.0-mysql php8.0-odbc php8.0-opcache php8.0-pgsql php8.0-phpdbg php8.0-pspell php8.0-readline \
php8.0-snmp php8.0-soap php8.0-sqlite3 php8.0-sybase php8.0-tidy php8.0-xml php8.0-xsl php8.0-zip
@ziadoz
ziadoz / homestead.sh
Last active Oct 14, 2020
Add and Remove Laravel Homestead Root CA to and from the macOS Keychain
View homestead.sh
sudo security delete-certificate -c "Homestead homestead Root CA" /Library/Keychains/System.keychain 2> /dev/null
sudo security add-trusted-cert -d -r trustRoot -p ssl -k /Library/Keychains/System.keychain ~/Projects/homestead/ca.homestead.homestead.crt 2> /dev/null
function homestead() {
( cd ~/Projects/homestead && vagrant $* )
if [[ "$1" == "destroy" ]]; then
sudo security delete-certificate -c "Homestead homestead Root CA" /Library/Keychains/System.keychain 2> /dev/null
fi