Skip to content

Instantly share code, notes, and snippets.

View atelierbram's full-sized avatar

Bram de Haan atelierbram

View GitHub Profile
@atelierbram
atelierbram / start-over-in-github.md
Created January 29, 2023 16:00
Start over in Github

Start over in GitHub

  • Create a new branch to point to your old code
  • Delete all the code and commit on master
  • Start your rewrite on master
# checkout the master branch
git checkout master
@atelierbram
atelierbram / jigsaw-static-site-set-active-class-in-navigation-menu.md
Last active January 28, 2023 15:21
Jigsaw Static Site - Set active class in navigation menu

Jigsaw Static Site - Set active class in navigation menu

Set a custom front matter variable "slug" in top of your post.blade.md file which is the same as the filename, here: this-post-example.blade.md

---
extends: _layouts.post
section: content
title: This Post Example
slug: this-post-example
@atelierbram
atelierbram / lazy-loading-video.md
Last active October 6, 2025 16:15
Lazy loading video

Lazy loading video

<video class="lazy" autoplay muted loop playsinline width="610" height="254" poster="one-does-not-simply.jpg">
  <source data-src="one-does-not-simply.webm" type="video/webm">
  <source data-src="one-does-not-simply.mp4" type="video/mp4">
</video>

You'll notice the addition of the poster attribute, which lets you specify a placeholder to occupy the <video> element's space until the video is lazy-loaded. As with the <img> lazy-loading examples, stash the video URL in the data-src attribute on each <source> element. From there, use JavaScript code similar to the Intersection Observer-based image lazy loading examples:

@atelierbram
atelierbram / responsive-images-in-wordpress-with-advanced-custom-fields-pro.md
Last active January 14, 2023 12:25
Responsive images in WordPress using srcset with Advanced Custom Fields Pro plugin

Responsive images in WordPress using srcset with Advanced Custom Fields Pro plugin

in functions.php:

add_filter( 'acf_the_content', 'wp_make_content_images_responsive' );

in template.php:

$image = get_field('my_image');
@atelierbram
atelierbram / create-a-persistent-directory-stack-in-zsh.md
Last active October 31, 2023 16:58
Create a persistent directory stack in zsh
@atelierbram
atelierbram / index.html
Created February 17, 2021 20:40 — forked from prof3ssorSt3v3/index.html
Code for youtube video on popstate, hashchange, and history.state
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>History popstate and hashchange Events</title>
<link rel="stylesheet" href="./main.css" />
</head>
<body>
@atelierbram
atelierbram / wordpress-image.md
Last active September 5, 2021 12:05
WordPress Thumbnail Image
<?php $imgPlaceholder3x2 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAQAAAA3fa6RAAAAEElEQVR42mM88J8BCBghFAAfUgOBvlG2dAAAAABJRU5ErkJggg==";
if( !empty(get_the_post_thumbnail()) ) {
  the_post_thumbnail( 'post-thumbnail', array(
    'alt' => the_title_attribute( array(
      'echo' => false,
    ) ),
    'src' => $imgPlaceholder3x2,
    'data-src' => get_the_post_thumbnail_url(),
    'loading' => 'lazy',
@atelierbram
atelierbram / php-get-index-inside-foreach-loop.md
Created February 5, 2021 13:05
PHP get index inside foreach loop

In the past, I’ve noticed that a lot of PHP beginners tend to struggle with the foreach loop. In some cases, it is because they have arrived from a language that only supports while loops and for loops.

Here is a basic example of a foreach loop:

<?php
foreach($array as $item){
 echo $item, '';
@atelierbram
atelierbram / Enable-Disable-Scrolling-in-iPhone-iPads-Safari.md
Created November 30, 2020 18:05
Enable/Disable Scrolling in iPhone/iPad’s Safari

To prevent user from scrolling the screen you need to redefine touch move event:

document.ontouchmove = function(e){ e.preventDefault(); }