Skip to content

Instantly share code, notes, and snippets.

View rungta's full-sized avatar

Prateek Rungta rungta

View GitHub Profile
@rungta
rungta / parse-youtube-vimeo-urls.php
Last active October 14, 2016 08:11 — forked from cballou/youtube-vimeo-embed-urls.php
Now returns video metadata instead of an embeddable URL
<?php
/**
* Given a string containing any combination of YouTube and Vimeo video URLs in
* a variety of formats (iframe, shortened, etc), each separated by a line break,
* parse the video string and determine it's host and ID.
*
* Data gets returned in the format:
*
* array(
* array(
@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
@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 / jquery.labels.js
Last active August 29, 2015 14:21
A jQuery plugin to find a form field’s associated `label` elements.
/*
jQuery plugin to find all <label> elements
associated with the currently selected form field
elements (typically <input>, <select> or <textarea>)
eg: $('input').labels();
*/
$.fn.labels = function () {
return this.map(function () {
if (this.labels) {
@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 / imageoptim.sh
Last active June 19, 2017 14:33
Script to optimize JPEG & PNG images (meant to be run as a @daily Cron job)
#!/bin/bash
# Usage
# imageoptim.sh /path/to/images/dir
#
# See: https://gist.github.com/rungta/0cc3f68beee42008e5cf05b2aa526954
# Find image files modified in the last 24 hours
@rungta
rungta / main.custom.conf
Last active June 19, 2017 12:34
Apache config to disable .htaccess files & include it in .conf
# This file is for ServerPilot configurations
# and should be located at /etc/apache-sp/vhosts.d/<APPNAME>.d
# See: https://gist.github.com/rungta/fd7edc3940ca9279b2095fb961466b8d
<Directory ${DOCUMENT_ROOT}>
# Disable .htaccess files
AllowOverride None
# Include root/.htaccess file
# the last character is a glob so that it silently ignores missing file
@rungta
rungta / smoothscroll.jquery.js
Last active May 15, 2018 12:17
Smoothly scroll to in-page fragment links
// from https://css-tricks.com/snippets/jquery/smooth-scrolling/
// modified to use native scrollIntoView when supported
// Select all links with hashes
$('html').on('click', 'a[href*="#"]', function(event) {
// On-page links
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') &&
location.hostname == this.hostname
) {
@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
@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;
}