Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / commas.html
Last active December 20, 2023 20:47
HTML/CSS - Human List, Commas, Oxford Commas
<!DOCTYPE html>
<html>
<head>
<style>
:root {
--commas-separator: ", ";
--commas-last-separator: " & ";
}
ul.commas,
@ziadoz
ziadoz / old-reddit-regex.txt
Last active December 13, 2023 23:12
StopTheMadness - Old Reddit Redirect Regular Expression
Redirect from New Reddit to Old Reddit, but ignoring media links, which break and point to a Lady Gaga nice hat page.
Links:
https://old.reddit.com/r/bugs/comments/15p1ctt/why_does_clicking_any_image_on_reddit_open_the/
https://github.com/tom-james-watson/old-reddit-redirect/blob/master/background.js
https://underpassapp.com/StopTheMadness/support-chrome.html#redirects
https://gist.github.com/msanders/52700d5c5ed76f1114594ddb862b530e
Pattern:
/^https?://www\.reddit\.com(?!/(?:(?:media|gallery|settings)\b|r/\w+/s/))([/#?].*)?$/
@ziadoz
ziadoz / count_max_multi_array.php
Last active December 8, 2023 16:40
PHP - Get Maximum Count of Multi-Dimensional Array
<?php
// @see: https://stackoverflow.com/questions/2189479/get-the-maximum-value-from-an-element-in-a-multidimensional-array
$array = [
'foo' => [1, 2, 3],
'bar' => [1],
'baz' => [1, 2],
];
echo count(max($array)); // 3
@ziadoz
ziadoz / php80_attributes.php
Last active November 27, 2023 11:00
Using PHP 8.0 Attributes/Annotations To Decorate Functions
<?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 / macos-ms-teams-audio-driver-issues.txt
Last active November 13, 2023 09:31
macOS Microsoft Teams Audio Driver Issues
In the middle of a Zoom call my audio in/out devices changed to “Microsoft Teams Audio Devices”, despite no longer having Microsoft Teams installed.
It turns out Teams leaves its audio driver on your system running, and it occasionally decides to make itself the default.
I had to delete: /Library/Audio/Plug-Ins/HAL/MSTeamsAudioDevice.driver in the end to fix it:
sudo rm -rf /Library/Audio/Plug-Ins/HAL/MSTeamsAudioDevice.driver
https://forums.macrumors.com/threads/how-to-uninstall-core-audio-driver-msteamsaudiodevice-driver.2344450/
@ziadoz
ziadoz / debug.md
Created September 26, 2023 11:28
Debugging Dusk/Codeception and ChromeDriver

Start ChromeDriver with logging enabled:

/usr/bin/chromedriver --url-base=/wd/hub --allowed-ips="" --port=9515 --log-level=INFO --log-path=/tmp/chromedriver.log

Run Dusk/Codeception:

php artisan dusk
@ziadoz
ziadoz / raw_sql.php
Last active September 21, 2023 09:41
Laravel - QueryExecuted To Raw SQL
<?php
// Before Laravel 10.15.0
function prepareQuery(QueryExecuted $query): string
{
return count($query->bindings) > 0
? vsprintf(str_replace(['%', '?'], ['%%', '%s'], $query->sql), array_map(fn ($value) => (is_numeric($value) ? $value : "'" . $value . "'"), $query->bindings))
: $query->sql;
}
prepareQuery($query);
@ziadoz
ziadoz / menu-icons.txt
Created July 25, 2023 15:53
Menu Icons
Hamburger Menu (☰)
Meatball Menu (⋯)
@ziadoz
ziadoz / test.sh
Created September 21, 2023 09:40
Test PHP Projects Using Docker
docker run --rm --interactive --tty --volume $PWD:/app composer install
docker run -it --rm --name laravel-dusk -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:8.2-cli php vendor/bin/phpunit
@ziadoz
ziadoz / debounce-keyup.js
Created July 5, 2012 17:03
jQuery Debounce Key Up
// Throttle / Debounce Plugin: http://benalman.com/projects/jquery-throttle-debounce-plugin/
$(document).ready(function() {
var callback = function(event) {
event.preventDefault();
// Do exciting things here.
};
$('form.search').on({
submit: callback,