Skip to content

Instantly share code, notes, and snippets.

View hadl's full-sized avatar

Andreas von Bibow hadl

View GitHub Profile
@hadl
hadl / slider-lazysizes.js
Last active July 1, 2020 08:20
Flickity & Lazysizes
/* eslint-disable no-underscore-dangle,prefer-rest-params */
import Flickity from 'flickity';
(() => {
const oldFlickityCreate = Flickity.prototype._create;
Flickity.prototype._create = function create() {
const that = this;
if (this.element.addEventListener) {
@hadl
hadl / slider-prev-next-buttons.js
Created July 1, 2020 08:23
Flickity next/prev buttons disable on "last page" when using contain
import Flickity from 'flickity';
(() => {
const { PrevNextButton } = Flickity;
const parentUpdate = PrevNextButton.prototype.update;
PrevNextButton.prototype.update = function update() {
parentUpdate.call(this);
if (this.parent.slideableWidth < this.parent.size.innerWidth) {
@hadl
hadl / microtime_diff.php
Last active March 5, 2021 04:05
PHP Microtime Diff -- Calculate a precise time difference
<?php
/**
* Calculate a precise time difference.
* @param string $start result of microtime()
* @param string $end result of microtime(); if NULL/FALSE/0/'' then it's now
* @return flat difference in seconds, calculated with minimum precision loss
*/
function microtime_diff($start, $end = null)
{
if (!$end) {
@hadl
hadl / alter-twig.php
Last active May 27, 2021 13:47
patternlab node - engine-twig-php extend/alter twig
<?php
/**
* @param Twig_Environment $env - The Twig Environment - https://twig.symfony.com/api/1.x/Twig_Environment.html
* @param $config - Config of `@basalt/twig-renderer`
*/
function addCustomExtension(\Twig_Environment &$env, $config) {
$env->addExtension(new \Twig_Extension_Debug());
/**