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:4578295
Last active January 30, 2024 06:34
Gravity Forms - custom field validation function for checkboxes. Ensures all checkboxes have been checked.
// Replace 7 with the ID of your form and 13 with the ID of the field you want to force "all required"
// http://www.gravityhelp.com/documentation/page/Gform_field_validation
add_filter("gform_field_validation_7_13", 'validate_tcs', 10, 4);
function validate_tcs($result, $value, $form, $field) {
// Convert the checkbox input name value (returned as part of "field")
// into the "underscored" ID version which is found in the $_POST
foreach ($field['inputs'] as $input) {
$input_post_value = 'input_' . str_replace('.', '_', $input['id']);
@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 / 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 / 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;
@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 / 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 / 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