Skip to content

Instantly share code, notes, and snippets.

View marcus-at-localhost's full-sized avatar
💭

Marcus marcus-at-localhost

💭
View GitHub Profile
@marcus-at-localhost
marcus-at-localhost / inject-script.js
Created May 27, 2024 21:28 — forked from umayr/inject-script.js
How to inject the script in the body of the document and wait till it has been loaded completely
// injects the script in the body of the document.
// returns a promise that gets resolves once the script has been loaded in the document
export const injectScript = (url, document = window.document) => {
const script = document.createElement('script');
script.src = url;
script.type = 'text/javascript';
script.async = true;
const body = document.getElementsByTagName('body')?.[0] ?? null;
if (body === null) {
@marcus-at-localhost
marcus-at-localhost / recover-deleted-branch.sh
Created May 27, 2024 21:26 — forked from umayr/recover-deleted-branch.sh
How to recover a deleted branch
## Pre-requisite: You have to know your last commit message from your deleted branch.
git reflog
# Search for message in the list
# a901eda HEAD@{18}: commit: <last commit message>
# Now you have two options, either checkout revision or HEAD
git checkout a901eda
# Or
git checkout HEAD@{18}
@marcus-at-localhost
marcus-at-localhost / List all Hard Links and Junctions.md
Created January 7, 2024 08:56
List all Hard Links and Junctions.md
@marcus-at-localhost
marcus-at-localhost / Simple template string replacement with strstr.md
Created August 17, 2023 17:58
Simple template string replacement with strstr.md

...instead of sprintf or str_replace[^1] in #php #string #template #pitfall

$strTemplate = "My name is :name, not :name2.";
$strParams = [
  ':name' => 'Dave',
  'Dave' => ':name2 or :password', // a wrench in the otherwise sensible input
  ':name2' => 'Steve',
 ':pass' =&gt; '7hf2348', // sensitive data that maybe shouldn't be here
@marcus-at-localhost
marcus-at-localhost / How to create a nested data-transfer-object (DTO) array with different types.md
Created July 29, 2023 07:57
How to create a nested data-transfer-object (DTO) array with different types.md
@marcus-at-localhost
marcus-at-localhost / Results of POST Request in Browser Window via Browser Console.md
Created July 29, 2023 07:48
Results of POST Request in Browser Window via Browser Console.md

#js

  1. Open network tab in #dev-tools
  2. Right click on request and copy as fetch
  3. Add the .then() part to the fetch() and send the request
  4. Result will be inserted in browser main window
fetch("https://teeeeeessssstttttt.com/ticket/", {
// This is meant to be in a html head script tag
// checkboxes are very inconvenient in html and will serialize nothing when the checkbox is unchecked
// instead of using hx-vals and writting a bit of JSON each time you have a checkbox I decided to fix it globally:
window.onload = function() {
document.body.addEventListener('htmx:configRequest', function(evt) {
const isInput = evt.detail.elt.tagName == 'INPUT';
const isCheckbox = evt.detail.elt.type == 'checkbox';
const isNotChecked = evt.detail.elt.checked == false;
if(isInput && isCheckbox && isNotChecked) {
const name = evt.detail.elt.name;

HTMX and Bootstrap Toasts

Just a little demo how to use bootstraps toasts component with HTMX and custom triggers. Toasts are stackable and grouped by message (so the same message doesn't pop up several times, when already open.

A Pen by Marcus at Localhost on CodePen.

License.

@marcus-at-localhost
marcus-at-localhost / htmx_question.md
Created May 1, 2023 00:22
Find a performant approach to interact with HX-Trigger in HTMX

V1

This listens for a HX-Trigger moGetBookmarkButton_ID event on the #bookmark_item_* element to trigger hx-get

kirby()->response()->header('HX-Trigger','moGetBookmarkButton_' . $product->id())
//kirby()->response()->header('HX-Trigger','moGetBookmarkButton_b2')