Skip to content

Instantly share code, notes, and snippets.

View surdaft's full-sized avatar
🤓

SurDaft - Jack Stupple surdaft

🤓
View GitHub Profile
@surdaft
surdaft / humanize.php
Last active August 7, 2017 11:46
Humanize camelCase / PascalCase words
<?php
// Humanize pascalCase / camelCase
// http://stackoverflow.com/questions/4519739#answer-7729790
$regex = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/x';
$example = 'GooglePlus';
$converted = implode(' ', preg_split($regex, $example));
@surdaft
surdaft / dimonx_breadcrumbs.php
Last active April 12, 2017 12:52
Wordpress breadcrumbs
<?php
// Copied from https://github.com/benbuildsstuff/base
function dimox_breadcrumbs() {
$showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
$delimiter = '/'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
@surdaft
surdaft / no_select.css
Created April 12, 2017 16:17
CSS to disable text highlighting
/**
* http://stackoverflow.com/questions/826782/how-to-disable-text-selection-highlighting-using-css
*/
.noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
@surdaft
surdaft / links.txt
Created May 11, 2017 09:50
Calculate aspect ratio percentage.
@surdaft
surdaft / bootstrap_config.json
Last active August 7, 2017 11:47 — forked from anonymous/config.json
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@surdaft
surdaft / nav.php
Created June 6, 2017 08:23
Get primary nav with nav container
<?= wp_nav_menu([
'menu' => 'primary_nav',
'container' => 'nav',
'container_class' => 'primary-nav',
'item_spacing' => 'discard'
]); ?>
@surdaft
surdaft / addEventListener-polyfill.js
Created August 7, 2017 09:47
Add Event Listener
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
(function() {
if (!Event.prototype.preventDefault) {
Event.prototype.preventDefault=function() {
this.returnValue=false;
};
}
if (!Event.prototype.stopPropagation) {
Event.prototype.stopPropagation=function() {
this.cancelBubble=true;
<?php
function humanize_filesize($size, $precision = 0) {
if ($size !== 0) {
$base = log($size) / log(1024);
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$size = round(pow(1024, $base - floor($base)), $precision);
$unit = $units[floor($base)];
} else {
$unit = 'B';
@surdaft
surdaft / whichTransition.js
Created September 8, 2017 13:40
Transition end stuff
function whichTransitionEvent() {
var t,
$e = document.createElement('whatever'),
transitions = {
'transition': 'transitionend',
'OTransition': 'oTransitionEnd',
'MozTransition': 'transitionend',
'WebkitTransition': 'webkitTransitionEnd'
};
@surdaft
surdaft / serve-wordpress-theblueskitchen.sh
Last active October 20, 2017 10:22
Nginx configurations for Homestead
#!/usr/bin/env bash
declare -A params=$6 # Create an associative array
paramsTXT=""
if [ -n "$6" ]; then
for element in "${!params[@]}"
do
paramsTXT="${paramsTXT}
fastcgi_param ${element} ${params[$element]};"
done
fi