Skip to content

Instantly share code, notes, and snippets.

View getdave's full-sized avatar
🏖️
AFK - I may not respond for a while...

Dave Smith getdave

🏖️
AFK - I may not respond for a while...
View GitHub Profile
@getdave
getdave / 301-redirect-checker.js
Last active June 5, 2017 15:50
Basic 301 redirect checker using NodeJS
var Crawler = require("crawler");
var map = require("lodash.map");
var chalk = require('chalk');
var errorStyle = chalk.bold.red;
var successStyle = chalk.bold.green;
var errors = [];
var c = new Crawler({
rateLimit: 200,
@getdave
getdave / Example of pipe()
Created May 31, 2017 10:40
A quick demonstration of the use of a pipe function
const pipe = (...funcs) => seed => {
return funcs.reduce( (acc, func) => {
return func(acc);
}, seed);
}
const reverseWord = (val) => {
return val.split("").reverse().join('');
};
@getdave
getdave / gist:a39175e3d33dc877f56c63e389f5f028
Last active June 5, 2017 15:48
Constructor Functions in JavaScript
const Person = function(name) {
this.name = name; // set instance property
}
// Define "shared" methods on prototype property
Person.prototype.greet = function() {
console.log(`Hello ${this.name}!`);
}
const dave = new Person('David');
@getdave
getdave / classical-js-with-sugar.js
Created May 16, 2017 12:50
Example of Classical Inheritance
class Appliance {
turnOn() {
console.log(this.type + " now online");
}
}
class Oven extends Appliance {
constructor() {
this.type = "Oven";
}
@getdave
getdave / performance-scroll-handling.js
Created May 13, 2017 14:28
Performant Handling of Scroll Events
var lastScrollY = 0;
var ticking = false;
var windowMiddle = $(window).height()/2;
var scrollCallback = function scrollCallback(e) {
var elementClosestToMiddle = _this.findElementClosestToMiddle(elements, {
windowMiddle: windowMiddle
});
@getdave
getdave / 0_reuse_code.js
Created December 14, 2015 12:46
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@getdave
getdave / make-page-editable.txt
Created November 27, 2015 14:05
Add this to your browser bookmarks to make the entire page's text editable. Handy for quick text edits.
javascript:(function()%7Bdocument.querySelector('body').setAttribute('contenteditable'%2C true)%7D)()
@getdave
getdave / strip-unwanted-gravity-forms-jquey-and-inline-scripts.php
Created November 12, 2015 12:14
Remove Gravity Forms jQuery and all inline <script> tags
/**
* Force GFORM Scripts inline next to Form Output
*
* force the script tags inline next to the form. This allows
* us to regex them out each time the form is rendered.
*
* see strip_inline_gform_scripts() function below
* which implements the required regex
*/
function force_gform_inline_scripts() {
@getdave
getdave / wp-output-buffered-template-include.php
Last active August 29, 2015 14:27
A useful utility function for WordPress projects which loads a given template using output buffering optionally including data to be passed into template
/**
* Output Buffered Load Template Part
* loads a given template part using output buffering
* optionally including $data to be passed into template
*/
function ob_load_template_part( $template_name, $data ) {
// Optionally provided an assoc array of data to pass to tempalte
// and it will be extracted into variables
@getdave
getdave / laravel-select-range-with-default
Last active June 27, 2018 02:16
Laravel selectRange with default
Form::macro('selectRangeWithDefault', function($name, $start, $end, $selected = null, $default = null, $attributes = [])
{
if ( is_null($default) ) {
return Form::selectRange($name, $start, $end, $selected, $attributes);
}
$range = array_combine($range = range($start, $end), $range);
$range = [null => $default] + $range;