Skip to content

Instantly share code, notes, and snippets.

View tomhazledine's full-sized avatar

Tom Hazledine tomhazledine

View GitHub Profile
@tomhazledine
tomhazledine / gist:2755c26dc685be756a3a
Created May 16, 2014 12:39
Fallback function for Advanced Custom Fields plugin for Wordpress
// Fallback if ACF plugin doesn't exist
/**
* Return a custom field stored by the Advanced Custom Fields plugin
*
* @global $post
* @param str $key The key to look for
* @param mixed $id The post ID (int|str, defaults to $post->ID)
* @param mixed $default Value to return if get_field() returns nothing
* @return mixed
* @uses get_field()
@tomhazledine
tomhazledine / folderStructure.txt
Last active August 29, 2015 14:22
Basic Gulp setup
_uncompressed/
icons/ ~ SVG icons go here
scss/
images/
js/
custom/ ~ JS partials live here
static/ ~ "static" files are *not* concatenated into app.min.js
jquery/
vendor/ ~ plugins etc. These are concatenated into app.min.js
<script src="/path/to/styleFreeAudio.min.js"></script>
<script src="/path/to/yourCustom.js"></script>
@tomhazledine
tomhazledine / SCSS_linter.yml
Created June 19, 2015 09:34
Gulp SCSS Linter
# Default application configuration that all configurations inherit from.
linters:
BorderZero:
enabled: true
CapitalizationInSelector:
enabled: true
ColorKeyword:
enabled: true
@tomhazledine
tomhazledine / birthday.js
Created August 30, 2017 16:19
Instructions for proper conduct at the party
let now = Date.now() / 1000;
if ( now > 1504051200 && now < 1504137599) {
steve.work = false;
steve.beers++;
}
@tomhazledine
tomhazledine / convert_number_to_words.php
Last active July 6, 2019 00:34
Convert Numbers Into Words
<?php
/**
* DISPLAY NUMBERS
*
* Convert raw numbers into human-readable words.
*
* Borrowed (and very much simplified) from:
* http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
* @param integer $number Raw number.
* @return string Number as a word.
@tomhazledine
tomhazledine / calculate_reading_time.php
Created November 16, 2016 08:30
Calculate Reading Time (for WordPress content)
<?php
/**
* READING TIME
*
* Calculate an approximate reading-time for a post.
*
* @param string $content The content to be measured.
* @return integer Reading-time in seconds.
*/
function reading_time( $content ) {
@tomhazledine
tomhazledine / known-pleasures-utils.js
Created March 27, 2024 18:12
Generate random-ish bell curve data
export const generateRandomBellCurveData = (size, min = 0, max = 100) => {
// Function to add pronounced randomness to the curve
const randomize = (val, min, max, noiseLevel = 0.5) => {
// Apply random noise based on noise level
const noise = (Math.random() * 2 - 1) * noiseLevel;
return Math.max(min, Math.min(max, val + noise));
};
// Generate Y values with normal distribution characteristics
const yValues = Array.from({ length: size }, (_, i) => {