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 / 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' => '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')
@marcus-at-localhost
marcus-at-localhost / Misc HTMX Pattern.md
Last active September 3, 2023 12:40
Misc HTMX Pattern.md

Just things I find, but not need right now #htmx

Trigger Third Party Behavior

bigskysoftware/htmx#1158 (comment)

htmx.onLoad(function (content) {
	content.querySelectorAll('[data-dismiss-target]').forEach(triggerEl => {
		const targetEl = document.querySelector(triggerEl.getAttribute('data-dismiss-target'))
@marcus-at-localhost
marcus-at-localhost / Show Error Page in Controller.md
Created March 18, 2023 09:24
Show Error Page in Controller.md

#kirby #php

<?php

return function ($page, $pages, $kirby, $site) {
	/**
	 * Don't show old applications
	 */
	if ( $page-&gt;dateFrom()-&gt;toDate() &gt; time() || $page-&gt;dateTo()-&gt;toDate() &lt; time()) {