Skip to content

Instantly share code, notes, and snippets.

@c-kick
c-kick / hnl.debounce.v4.js
Last active March 12, 2023 17:42
JavaScript function prototype debouncer v4.1 - debounces functions that are prone to repetitive calling (on events such as mousewheel, orientationchange, resize, etc). Demo: https://code.hnldesign.nl/demo/hnl.debounce.html
/**
* JavaScript function prototype debouncer 4.3 - 2010-2022 hnldesign.nl - Klaas Leussink
* Demo: https://code.hnldesign.nl/demo/hnl.debounce.html
*
* Based on code by Paul Irish and the original debouncing function from John Hann
* http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
* Register deBouncer as a function prototype.
*
* All debounced variants of the function (depending on the supplied debouncing parameters (see below)
* are stored inside a 'dbObj' Object inside the debounced function.
@c-kick
c-kick / hnl.inertial.js
Created November 17, 2014 21:50
jQuery - Simulate Momentum Scrolling
/**
* jQuery inertial Scroller v1.5
* (c)2013 hnldesign.nl
* This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
*
* More information: http://www.hnldesign.nl/work/code/momentum-scrolling-using-jquery/
*/
/*jslint browser: true*/
/*global $, jQuery*/
@c-kick
c-kick / hnl.collision.detection.js
Last active January 26, 2023 07:50
jQuery - Collision detection for absolute positioned elements
/*!
* jQuery Collision Detection - v1.0 - 1/7/2014
* http://www.hnldesign.nl/work/code/collision-prevention-using-jquery/
*
* Copyright (c) 2014 HN Leussink
* Dual licensed under the MIT and GPL licenses.
*
* Example: http://code.hnldesign.nl/demo/hnl.collision.detection.html
*/
@c-kick
c-kick / schedule_booleans.yaml
Last active October 31, 2022 09:59
Automation which uses schedules to set two indicators (booleans): a morning schedule and a home indicator. Also provides schedule/calendar overrides. See description for usage.
#Blueprint by Klaas Leussink / hnldesign.nl (c) 2022
blueprint:
name: Set schedule-related booleans
source_url: https://gist.github.com/c-kick/b4dcdae9d9fa85ca8c51cdedd7293bf5
description: >-
This automation uses schedules to set two indicators (booleans): a morning schedule (useful for short morning routines on working days) and a home indicator (useful for indicating people are home, until they go to bed). It also includes an option to use a holiday calendar, which sets the home indicator on the specified start and end times if the current day is a holiday. Another option is a vacation override, which - when set to active - ignores *all* schedules/calendars and uses the specified 'vacation schedule' instead.
domain: automation
input:
morning_routine_schedules:
name: Morning schedule(s)
@c-kick
c-kick / motion_light_with_override.yaml
Last active October 31, 2022 09:41
A Home Assistant blueprint that can be used to have a motion sensor switch on (a) device(s), but allow the turning off procedure (after no motion is detected anymore) to be overridden by a switch/button. Useful if you need to activate a light upon entry, and turn off after no motion (most cases), but keep the option to force the light to stay on.
#Blueprint by Klaas Leussink / hnldesign.nl (c) 2022
blueprint:
name: Motion Light with override
source_url: https://gist.github.com/c-kick/32234ea474f6b854a861853b17b881ce
description: >-
This blueprint can be used to have a motion sensor switch on (a) device(s), but allow the turning off procedure (after no motion is detected anymore) to be overridden by a (ZHA) switch/button. Useful if you need to activate a light upon entry, and turn off after no motion (most cases), but keep the option to make the light stay on if you're planning on spending more time in the area (e.g. a shed).
Note: if you need to know what is happening, uncomment the debug message lines.
domain: automation
input:
motion_sensor:
@c-kick
c-kick / arc-vt.js
Last active October 19, 2022 08:59
This nodejs script is originally aimed at (Plex) LG OLED users that don't have DTS decoding. It auto-converts audio in video files to something other than DTS (AC3) if applicable (see description in file)
#!/usr/bin/env node
/*
ARC-VT: Audio-stream Reorganizer, Converter & Video Transcoder by Klaas Leussink / hnldesign (C) 2022-2023
This nodejs script is originally aimed at non-DTS LG OLED owners running Plex on a Synology Diskstation.
The problem being that Plex will stubbornly offer the DTS track for playback, producing no sound. And when
asked to convert, playback is choppy/hangs every x seconds. The most solid solution is to make sure the
first available audio stream is a non-DTS (e.g. AC3) codec. This script automates that process:
@c-kick
c-kick / hnl.setBreakpoints.js
Last active March 23, 2022 10:11
setBreakpoints - Adds the current breakpoint-name (as specified in the 'breakpoints' const) to the body class and notifies anyone listening of the change via the 'breakPointChanged' event.
/** This script adds the current breakpoint-name (as specified in the 'breakpoints' const)
* to the body class and notifies anyone listening of the change via the 'breakPointChanged' event.
*
* Default breakpoint names and cutoff pixel values taken from Bootstrap 5's default responsive breakpoints:
* https://getbootstrap.com/docs/5.0/layout/breakpoints/
*
* Usage:
* - include the script into your page and the class is updated, and will continue to update whenever
* the width of the window changes enough to trigger another breakpoint.
* - optionally listen for the event via:
@c-kick
c-kick / hnl.taphover.js
Last active January 19, 2021 23:00
jQuery - Mouse hover on touch devices
//26-5-2020 update: possibly shorter, and better, since 'click' now fires on a tap, and is not prevented by the previous script.
//Also: more concatenation.
$(document).on('touchstart, click', 'a.taphover', function (e) {
if (!$(this).hasClass('hover')) { e.preventDefault(); }
$('.taphover').not($(this).toggleClass('hover')).removeClass('hover');
});
//the previous version:
//taphover - a solution to the lack of hover on touch devices.
@c-kick
c-kick / csp-generator.php
Last active December 10, 2020 20:55
Generates a Content Security Policy using easy definable arrays. See code docs for example.
/**
* CSP Generator v0.2 (C) 2020-10-12 hnldesign.nl / Klaas Leussink
* @param array $rules
* Rules, specified as an array with rulesets (array) or rules (string). Note that 'hosts' are specified as an array inside the ruleset:
* note: it's easier to define hosts in the $domains array (see second param)
* array(
* 'default-src' => array (
* 'self',
* 'data',
* 'unsafe-eval',
@c-kick
c-kick / hnl.debounce.v3.js
Last active November 23, 2020 23:30
JavaScript function prototype debouncer v3.0 - debounces functions that are prone to repetitive calling (on events such as mousewheel, orientationchange, resize, etc)
/**
*
*
* DEPRECATED, SEE NEW VERSION AT https://gist.github.com/c-kick/d359fce36257cf4c9fb5ea5f2c0033b6
*
*
* JavaScript function prototype debouncer 3.0 - hnldesign.nl
* Based on code by Paul Irish and the original debouncing function from John Hann
* http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
* Register deBouncer as a function prototype.