Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
ivanhoe011 / get-filters.js
Created April 10, 2024 07:28
Get all filters from the url's query (following jsonapi.org filters format)
/**
* Get all filters w/ regexp, because UrlSearchParams sux
*
* @param string url
* @return Object
*/
function extractFilters(url) {
return url.matchAll(
/[&?]filter\[([^\]]+)\]=([^&]+)/g
)
@ivanhoe011
ivanhoe011 / json_dd.php
Last active March 29, 2024 12:42
Workaround for Laravel's dd() debugging in new versions of Chrome
<?php
/**
* New versions of Chrome will not render html responses inside of ajax requests that requested json, which
* breaks Laravel's dd() helper method as well as eloquents' ->dd() methods, making it far more complicated
* to see what the generated SQL looks like. This is a simple workaround:
*/
// instead of `dd($foo);`
return response()->json($foo, 500);
@ivanhoe011
ivanhoe011 / html_clipboard.js
Created March 2, 2023 11:59
Get html from clipboard with js
document
// can be any element that knows how to recieve the paste event
.getElementById('someElement')
// add event listener
.addEventListener('paste', e => {
if (! e.clipboardData.types.includes('text/html')) {
// if there's no html on the clipboard ignore it
return;
}
@ivanhoe011
ivanhoe011 / variousCountryListFormats.js
Created March 2, 2023 11:39 — forked from incredimike/variousCountryListFormats.js
List of Countries in various Javascript data structures: Alphabetical country lists & Country data objects.
// Lists of countries with ISO 3166 codes, presented in various formats.
// Last Updated: July 30, 2020
// If you're using PHP, I suggest checking out:
// https://github.com/thephpleague/iso3166
// or Laravel: https://github.com/squirephp/squire
//
// JS developers can check out:
// https://www.npmjs.com/package/iso3166-2-db
//
@ivanhoe011
ivanhoe011 / monitor.sh
Created December 18, 2022 11:51
Monitor bg running script for errors and sound an alarm (on Mac)
tail -f nohup.out | grep -i error | while read line; do say 'Error!'; done
@ivanhoe011
ivanhoe011 / simple.sh
Created December 14, 2022 23:41
Bash script simple template
#!/bin/bash
#
# This script...
#
# Usage: ...
##
set -o pipefail
set -ex
@ivanhoe011
ivanhoe011 / shasum_example.sh
Created December 7, 2022 17:41
Check the sha256 signature without creating a file with the signature, just pass the string
echo "<sha256_signature> *<file_name>" | shasum -a 256 -c
@ivanhoe011
ivanhoe011 / laravel-services.md
Created December 6, 2022 09:32
Laravel services

First class open-source packages

  • Dusk - Browser Testing
  • Envoy - Task Runner
  • Horizon - Queues Manager
  • Jetstream - Frontend Scaffolding
  • Fortify - Headless auth backend
  • Passport - OAuth 2.0
  • Sanctum - Token-based auth
  • Scout - Full-text search
@ivanhoe011
ivanhoe011 / removeEmptyProps.js
Last active March 22, 2022 07:25
Filter out empty properties from the object
/**
* Helper to filter out the empty properties(null, undefined, [], or '') from the given object
*
* @param {{}} obj
* @returns {{}}
*/
const removeEmptyProps = (obj) => {
return Object.keys(obj)
// remove params that are empty
.filter(key => {
@ivanhoe011
ivanhoe011 / clean_pdf.sh
Created January 29, 2022 00:55 — forked from sneakers-the-rat/clean_pdf.sh
Strip PDF Metadata
# --------------------------------------------------------------------
# Recursively find pdfs from the directory given as the first argument,
# otherwise search the current directory.
# Use exiftool and qpdf (both must be installed and locatable on $PATH)
# to strip all top-level metadata from PDFs.
#
# Note - This only removes file-level metadata, not any metadata
# in embedded images, etc.
#
# Code is provided as-is, I take no responsibility for its use,