Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / awesome-php.md
Last active July 13, 2024 05:29
Awesome PHP — A curated list of amazingly awesome PHP libraries, resources and shiny things.
@ziadoz
ziadoz / date-hms.js
Created July 9, 2024 11:13
JS - Get Hours, Minutes and Seconds from Date
console.log(
new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric' })
.formatToParts(new Date)
.map((part) => part.value)
.join('')
);
@ziadoz
ziadoz / php80_attributes.php
Last active June 16, 2024 08:19
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 / reading-list.js
Created June 3, 2024 19:54
Extract Safari Reading List Bookmarks
// Export bookmarks, open HTML, run this:
const links = [];
document.querySelectorAll('body > dt:nth-of-type(4) a').forEach((a) => {
links.push(a.getAttribute('href'));
});
links.join("\n");
@ziadoz
ziadoz / unbookmark.js
Last active June 3, 2024 19:28
Mastodon - Delete All Bookmarks
// Inspired by Twitter Unfollow All: https://gist.github.com/ziadoz/caa882e75c11be9e8064e570ffec1f5f
(() => {
const $bookmarkButtons = 'button.status__action-bar__button.bookmark-icon';
const retry = {
count: 0,
limit: 3,
};
@ziadoz
ziadoz / .gitattributes
Last active June 3, 2024 05:40
Prevent Git Managing CSV Line Endings
# 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 / git-obliterate.sh
Created May 24, 2024 20:36
Git Obliterate - Remove files from entire Git repository history
#!/usr/bin/env bash
# @link: https://github.com/tj/git-extras
# Install
brew install git-extras
# Usage
git-obliterate secrets.json
@ziadoz
ziadoz / unfollow.js.md
Created April 26, 2024 19:31 — forked from JamieMason/unfollow.js.md
Unfollow everyone on twitter.com

Unfollow everyone on twitter.com

  1. Go to https://twitter.com/YOUR_USER_NAME/following
  2. Open the Developer Console. (COMMAND+ALT+I on Mac)
  3. Paste this into the Developer Console and run it
// Unfollow everyone on twitter.com, by Jamie Mason (https://twitter.com/fold_left)
// https://gist.github.com/JamieMason/7580315
//
@ziadoz
ziadoz / dom-props.html
Created April 24, 2024 18:06
DOM Properties
<div id="app"></div>
<script>
const option = document.createElement('option');
option.value = 'Foo Bar';
const datalist = document.createElement('datalist');
datalist.id = 'foo-bar';
datalist.appendChild(option);
@ziadoz
ziadoz / halt_compiler.php
Last active April 23, 2024 17:55
Using PHP Halt Compiler
<?php
/**
* The __halt_compiler() function will stop the PHP compiler when called.
* You can then use the __COMPILER_HALT_OFFSET__ constant to grab the contents of the PHP file after the halt.
* In this example a PHP template is stored after the halt, to allow simple separation of logic from templating.
* The template is stored in a temporary file so it can be included and parsed.
*
* See: https://github.com/bobthecow/mustache.php/blob/dev/src/Mustache/Loader/InlineLoader.php
* http://php.net/manual/en/function.halt-compiler.php
*/