Skip to content

Instantly share code, notes, and snippets.

@royce002
royce002 / Script to drop into Google Sheets.js
Created April 16, 2020 02:45
Script to add to Google Sheets
// original from: http://mashe.hawksey.info/2014/07/google-sheets-as-a-database-insert-with-apps-script-using-postget-methods-with-ajax-example/
// original gist: https://gist.github.com/willpatera/ee41ae374d3c9839c2d6
function doGet(e){
return handleResponse(e);
}
// Enter sheet name where data is to be written below
var SHEET_NAME = "Sheet1";
@royce002
royce002 / Google-Sheets-Form-Data-Submit.js
Created April 16, 2020 02:41
Adding form data to Google Sheets
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || "");
} else {
@royce002
royce002 / Auto-Comment WP Blacklist.txt
Last active March 25, 2020 19:11
Auto blacklist characters for WordPress
=================================================================
Ultimate Comment Blacklist
Source:
Ultimate Comment Blacklist for WordPress
https://perishablepress.com/wordpress-ultimate-comment-blacklist/
License:
@royce002
royce002 / BS4 Barebones Template.htm
Last active March 18, 2020 18:20
BS4.4.1 Bare Bones Bootstrap Template with CDN links
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Bare - Start Bootstrap Template</title>
<!-- Bootstrap core CSS -->
@royce002
royce002 / Get-Image-Caption-ShortCode-WP.php
Created March 9, 2020 18:52
Little snippet that fetches an image attachment's caption in WordPress.
<?php
function get_caption_directly($atts = array()) {
// set up default parameters
extract(shortcode_atts(array(
'id' => '52',
), $atts));
return wp_get_attachment_caption( $id );
}
@royce002
royce002 / .htaccess caching 30 days
Created February 12, 2020 20:15
.htaccess file to add 30 day caching to a directory
# BEGIN Expire headers
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/svg+xml "access plus 2592000 seconds"
ExpiresByType application/x-font-ttf "access plus 2592000 seconds"
@royce002
royce002 / keypress.js
Created February 6, 2020 02:53
This little function detects the arrow keys on a keyboard. 2 Functions , one in an if else and the other in a switch case.
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '38') {
// up arrow
}
else if (e.keyCode == '40') {
// down arrow
@royce002
royce002 / PHP If Date is Between.php
Created January 15, 2020 16:29
Sets the timezone, and checks current time to see if it lies between a start and ending range.
<?php
date_default_timezone_set('america/chicago');
$currentDayTime = new DateTime(); // Get Today's Date/Time
echo $currentDayTime->format('m-d-Y H:i') . "<br>";
$startDateTime = new DateTime('2020-01-15');
$startDateTime->setTime(8, 00);
echo $startDateTime->format('m-d-Y H:i') . "<br>";
@royce002
royce002 / wp-default-walker.php
Created January 10, 2020 03:25
WordPress default menu walker call
wp_nav_menu( array $args = array(
'menu' => "", // (int|string|WP_Term) Desired menu. Accepts a menu ID, slug, name, or object.
'menu_class' => "", // (string) CSS class to use for the ul element which forms the menu. Default 'menu'.
'menu_id' => "", // (string) The ID that is applied to the ul element which forms the menu. Default is the menu slug, incremented.
'container' => "", // (string) Whether to wrap the ul, and what to wrap it with. Default 'div'.
'container_class' => "", // (string) Class that is applied to the container. Default 'menu-{menu slug}-container'.
'container_id' => "", // (string) The ID that is applied to the container.
'fallback_cb' => "", // (callable|bool) If the menu doesn't exists, a callback function will fire. Default is 'wp_page_menu'. Set to false for no fallback.
'before' => "", // (string) Text before the link markup.
'after' => "", // (string) Text after the link mar
@royce002
royce002 / CurrencyFormatting.js
Created December 12, 2019 02:31
JavaScript function to format currency
function currencyFormat(num) {
return '$' + num.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
console.info(currencyFormat(2665)) // $2,665.00
console.info(currencyFormat(102665)) // $102,665.00