Skip to content

Instantly share code, notes, and snippets.

View lucas-pelton's full-sized avatar

Lucas Pelton lucas-pelton

View GitHub Profile
@vdbelt
vdbelt / cloudflare-purge-cache-service-worker.js
Created August 21, 2018 11:43
A CloudFlare service worker that proxies purge cache requests. Example: https://example.com/__purge_cache?zone=XX
addEventListener('fetch', event => {
event.respondWith(purgeCache(event.request))
})
async function purgeCache(request) {
const url = new URL(request.url)
@gvko
gvko / enumerate-dates-by-period.js
Last active December 23, 2021 15:41
Enumerate days, weeks, months or years
'use strict';
const moment = require('moment');
/**
* Returns a {key: value} object where the key is a start date and the value is the date + 1 of the type of interval
* to the start date. When for weeks or months, it shows just the first date of the week/month.
*
** For days (start: '2017-12-25', end: '2018-01-02', interval: 'day'):
{ '2017-12-25': '2017-12-26',
@imath
imath / tickets.php
Last active October 9, 2023 03:47
Using WP Statuses for custom Post Types.
<?php
/**
* Using WP Statuses for custom Post Types.
*
* @link http://github.com/imath/wp-statuses
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
@iksi
iksi / fluid-typography.css
Created January 14, 2016 11:45
Fluid typography between a min & max font-size and molten leading
/**
* Fluid typography between a min & max font-size and molten leading
* calc(minSize + (maxSize - minSize) * ((100vw - minPort) / (maxPort - minPort)));
*/
:root {
font-size: 100%;
}
body {
font-size: 1em;
@magnific0
magnific0 / wp_usermeta.md
Last active June 16, 2023 05:28
Show and Edit User Meta in Wordpress

Show and Edit User Meta in Wordpress

Description

This simple procedure will allow you to:

  1. Display user meta fields under in the user list as additional columns (Users > All Users).
  2. Display these fields on user profiles.
  3. Edit these fields under user edit.

This method works completely without plugins and involves just some functions and hooks in functions.php. Plugins like "User Meta Display" achieve this to some level, but treat custom meta fields completely different from the regular fields. They are shown and edited in seperate environment and fail to show the meta data is a table list. This method integrates custom user meta along with regular user (meta).

@mikeselander
mikeselander / gf-convert-to-timestamp.php
Created July 10, 2014 16:44
Gravity Forms doesn't offer a function to export a date field as a UNIX timestamp. This function will find all exported dates in a GF submission & convert it to UNIX, and then update the postmeta to the proper format - as is, it will ONLY work if you're using the Gravity Forms + Custom Post Types plugin to create or edit a post
add_action( 'gform_after_submission', '_convert_date_to_timestamp', 10, 2 ); // Extend
function _convert_date_to_timestamp( $entry, $form ) {
date_default_timezone_set ( "America/Denver" );
// Make sure that we're submitting a post before running the code
if ( $entry['post_id'] ){
foreach ( $entry as $key => $value ){
@codeguy
codeguy / slugify.js
Created September 24, 2013 13:19
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@PaulKinlan
PaulKinlan / criticalcss-bookmarklet-devtool-snippet.js
Last active April 2, 2024 02:45
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");