Skip to content

Instantly share code, notes, and snippets.

View rungta's full-sized avatar

Prateek Rungta rungta

View GitHub Profile
@rungta
rungta / checkboxscope.js
Last active July 19, 2024 08:19
Uncheck input[data-checkboxscope-input][type=checkbox] on a click outside [data-checkboxscope-container]
// Uncheck any `input[type=checkbox]` (`[data-checkboxscope-input]`)
// outside a defined scope area (`[data-checkboxscope-container]`)
//
// Eg:
//
// <div data-checkboxscope-container>
// <input data-checkboxscope-input type=checkbox>
// </div>
// <div>
// <!-- a click here will uncheck the checkbox above -->
@rungta
rungta / .tm_properties
Created July 1, 2024 16:48
TextMate 2 Craft CMS project file
# Add this file to the root of your Craft CMS project dir
exclude = "{$exclude,web/{cpresources,media,transcoder,images/*},storage/{backups,config-backups,config-deltas,runtime,logs},*.sql,.ddev/.*}"
includeDirectories = "{$includeDirectories,.ddev}"
excludeDirectories = "{$excludeDirectories,.ddev/*}"
@rungta
rungta / checkbox.required-any.js
Last active February 14, 2023 06:53
HTML validation polyfill for checkboxes to require at least one option with the same input name.
// Allow 'require-ing' at least one option from a list of checkboxes
// with the same name. Polyfill for modifying the default HTML behaviour
// which is requiring all checkboxes with the 'required' attribute
//
// eg:
// <input type=checkbox name=eg value=a data-required-any>
// <input type=checkbox name=eg value=b data-required-any>
// <input type=checkbox name=eg value=c data-required-any>
(function (window) {
#
# WARNING: This is not a complete NGINX configuration file
# It tries to highlight just the directives used to enable FastCGI microcaching
# as explained in my “Micro-caching in Nginx for High Performance” talk
# https://speakerdeck.com/rungta/micro-caching-in-nginx-for-high-performance
# Video: https://youtu.be/termdb4vepA?t=2199
#
http {
#...
@rungta
rungta / checkboxradio.js
Last active February 14, 2020 14:24
Make HTML Checkboxes behave like Radio Inputs in that only one can be selected at a time.
(function(w) {
function checkboxAsRadio(selector) {
return function (event) {
var el = event.target;
// only proceed if we have a matching checkbox
if (!(el instanceof HTMLInputElement && el.matches(selector))) {
return;
}
@rungta
rungta / jquery.external-links-new-window.js
Last active December 18, 2019 11:49 — forked from wpscholar/jquery.external-links-new-window.js
Open all external links in a new window
{# _init.twig #}
{#
Usage
extend `_init`
set `doNotCache` to true to exclude a page
set `cacheKey` to a string to cache a template globally
(as opposed to by URL). eg: 404 template
modify `cacheKeyPrefix` to include variation params, if any
#}
@rungta
rungta / fontloader.js
Last active May 1, 2019 06:10
Load CSS `@font-face` fonts by listening for font loading events. A workaround while we wait for browsers to support the `font-rendering: swap` property.
/**
* fontloader.js
Helps you avoid FOIT and progressively load in multiple
sets of webfonts as asynchronous non-blocking resources.
Apply them on the page when the fonts are ready, like so:
.title-type { font-family: serif; }
.prose-type { font-family: sans-serif; }
@rungta
rungta / _vanity_router.twig
Last active March 14, 2019 09:21
Vanity URL routing for Craft CMS
{# Treat the slug as a template path #}
{% set template = include(top_level_slug, ignore_missing = true) %}
{# Render the template contents if found, otherwise treat the slug as a username #}
{% if template is not empty %}
{{- template|raw -}}
{% else %}
{%- include 'users/_profile' with { username: top_level_slug } -%}
{% endif %}
@rungta
rungta / trello_to_markdown.py
Last active June 20, 2018 14:23
Render a Trello board’s contents from JSON into a more human readable format (Markdown).
#-*- coding: utf-8 -*-
"""
Render a Trello board's contents from JSON into a more human readable format (Markdown)
Sample output:
Board Name
==========
List Name