Skip to content

Instantly share code, notes, and snippets.

View atelierbram's full-sized avatar

Bram de Haan atelierbram

View GitHub Profile
@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(); }
@atelierbram
atelierbram / transfer-file-using-scp.md
Created July 7, 2020 13:35
scp method for remote file transfer using SSH

The easiest of these are scp or secure copy. While cp is for copying local files, scp is for remote file transfer. The main difference is that with scp you'll have to specify the remote host's DNS name or IP address and provide login credential for the command to work.

Steps to copy local and remote file using scp:

Copy single file from local to remote.

$ scp myfile.txt remoteuser@remoteserver:/remote/folder/
@atelierbram
atelierbram / wp-img-data-src-function.php
Last active September 5, 2021 13:06
Set data-src attribute in a function for lazy-loading of image (WordPress)
function rchv_projects_link() { ?>
<a class="grid_item-link gallery_item-link" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
<?php $imgPlaceholder = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk2A8AAMUAwUPJ2C4AAAAASUVORK5CYII="; ?>
<figure class="grid_item-figure gallery_item-figure">
<?php if( !empty(get_the_post_thumbnail()) ) {
the_post_thumbnail( 'post-thumbnail', array(
'alt' => the_title_attribute( array(
'echo' => false,
) ),
'src' => $imgPlaceholder,
@atelierbram
atelierbram / encoding-video.md
Created October 17, 2019 18:27 — forked from Vestride/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@atelierbram
atelierbram / querySelectorAll_Looping.js
Created November 14, 2018 20:07
A common need when writing vanilla JavaScript is to find a selection of elements in the DOM and loop over them. For example, finding instances of a button and attaching a click handler to them.
let buttons = document.querySelectorAll("button");
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
// http://kangax.github.io/compat-table/es6/#for..of_loops
for (const button of buttons) {
button.addEventListener('click', () => {
console.log("for of worked");
});
}