Skip to content

Instantly share code, notes, and snippets.

View trvswgnr's full-sized avatar
:octocat:
hardly workin'

Travis A. Wagner trvswgnr

:octocat:
hardly workin'
View GitHub Profile
!function() {
var doc = document,
htm = doc.documentElement,
lct = null, // last click target
nearest = function(elm, tag) {
while (elm && elm.nodeName != tag) {
elm = elm.parentNode;
}
return elm;
};
@whizark
whizark / class-naming-convention.md
Last active November 7, 2024 10:25
HTML/CSS Class Naming Convention #html #css #sass
@voku
voku / input_filter.php
Last active September 27, 2020 06:30
use input filter for php (get, post, get_post, session, cookie)
<?php
//define('SECONDS_IN_A_MINUTE', 60);
//define('SECONDS_IN_A_HOUR', 3600);
//define('SECONDS_IN_A_DAY', 86400);
//define('SECONDS_IN_A_WEEK', 604800);
//define('SECONDS_IN_A_MONTH', 2592000);
//define('SECONDS_IN_A_YEAR', 31536000);
/**
@andrewlimaza
andrewlimaza / rh_fields_example.php
Created December 15, 2016 14:04
Register Helper field type example shows an example of every possible field in Register Helper
<?php
/**
* This example is to show you the 'niche' options each Paid Memberships Pro - Register Helper Add-on field can take and how to use it.
* For more information on the Register Helper Add-on please visit https://www.paidmembershipspro.com/add-ons/free-add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
**/
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
@grimzy
grimzy / git-pull-all
Created September 15, 2017 02:15
Git pull all remote branches
#!/usr/bin/env bash
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
@shreyans94
shreyans94 / gist:05b10194cf2f57cf054a5cf3da3fd931
Created January 23, 2018 21:32
Display ACF for woocommerce variations in backend
// Render fields at the bottom of variations - does not account for field group order or placement.
add_action( 'woocommerce_product_after_variable_attributes', function( $loop, $variation_data, $variation ) {
global $abcdefgh_i; // Custom global variable to monitor index
$abcdefgh_i = $loop;
// Add filter to update field name
add_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
// Loop through all field groups
$acf_field_groups = acf_get_field_groups();
foreach( $acf_field_groups as $acf_field_group ) {
@trvswgnr
trvswgnr / fetch-all.ts
Created July 17, 2023 08:57
concurrent fetch with retry policy
export async function fetchAll(urls: string[], concurrency = 5, retryPolicy = defaultRetryPolicy): Promise<Response[]> {
const controller = new AbortController();
const semaphore = new Semaphore(concurrency);
const promises = urls.map(async url => {
await semaphore.acquire();
try {
return await fetchWithRetry(url, retryPolicy, controller.signal);
} catch (error) {
controller.abort(); // abort all requests on fatal error
throw error;
@trvswgnr
trvswgnr / tramp.ts
Last active July 11, 2024 18:59
trampoline typescript
/**
* Transforms a function that returns either a direct value or a thunk (a
* no-argument function that returns a value) into a function that only returns
* a direct value. It does this by repeatedly evaluating the function if it
* returns a thunk, until a direct value is obtained.
*
* @template T The type of the value to be returned by the trampoline function.
* @template A The type tuple representing the argument types accepted by the
* function f.
* @param f A function that takes arguments of type A and returns either a
@trvswgnr
trvswgnr / compress_video
Last active November 12, 2024 21:17
portable shell script to compress videos with ffmpeg
#!/bin/sh
print_usage() {
echo "usage: compress_video <input_file>"
echo "supported formats: mp4, webm, mkv, mov, avi, flv"
}
get_extension() {
f="${1##*/}"
case "$f" in
@trvswgnr
trvswgnr / levenshtein.ts
Last active September 27, 2024 03:56
levenshtein distance ts
export function levenshteinDistance(a: string, b: string): number {
if (typeof a !== "string" || typeof b !== "string") {
throw new TypeError("Arguments must be of type `string`");
}
if (arguments.length > 2) {
throw new RangeError("Too many arguments");
}
if (a === b) {