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 / gist:9605519
Created March 17, 2014 18:38
Regex search and replace for Compass/Bourbon SASS mixin.
@include border-radius\(([0-9]+px)+\);
@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 / 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 / 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 / Rename files with suffix before extension
Last active December 20, 2015 12:39
Rename a bunch of files and append a suffix before the file extension. Particularly useful for anyone using Grunticon's filename-based colour manipulation. https://github.com/filamentgroup/grunticon/issues/57
for f in *.svg; do mv $f `basename $f .svg`.colors-white.svg; done;
@getdave
getdave / pre-commit.sh
Created September 25, 2013 16:15
Git Pre-Commit hook bash script to stop people committing directly to the master branch. Typically useful in a GitFlow based workflow. Installation would be as simple as ```` ln -s ../../pre-commit.sh .git/hooks/pre-commit ````
git branch | grep "* master" && echo 'COMMIT REJECTED - you are not allowed to commit directly to the master branch you fool!'
@getdave
getdave / Pretty Git changelog between 2 commits
Last active December 24, 2015 21:59
Generate a list of changed files between two git commit SHA's.
git log --name-only --pretty=oneline --full-index SHA1..SHA2 | grep -vE '^[0-9a-f]{40} ' | sort | uniq
@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 / 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 / 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('');
};