Skip to content

Instantly share code, notes, and snippets.

View makingthingswork's full-sized avatar

Making Things Work makingthingswork

View GitHub Profile
@makingthingswork
makingthingswork / get-ordinal.js
Last active August 23, 2019 15:30
Get number as ordinal
//Returns the number as an ordinal eg. 1st, 2nd, 3rd, 4th etc.
var nth = function(o) {
return o+(['st','nd','rd'][(o+'').match(/1?\d\b/)-1]||'th');
}
@makingthingswork
makingthingswork / get-ordinal.php
Last active November 19, 2020 14:33
Get number as ordinal
<?php
//Returns the number as an ordinal eg. 1st, 2nd, 3rd, 4th etc.
function nth(num) {
nf = new NumberFormatter('en_GB', NumberFormatter::ORDINAL);
return nf->format(num);
}
?>
@makingthingswork
makingthingswork / create-percentage.scss
Last active November 19, 2020 14:37
Create percentage
// Cast number by * 1% to create percentage, appending a % sign just creates a string.
@function percentage($number) {
@return $number * 1%;
}
@makingthingswork
makingthingswork / remove-empty.php
Last active November 19, 2020 14:34
Remove empty indexes from array
<?php
function remove_empty_index(array arr) {
return array_filter(arr, 'strlen');
}
?>
@makingthingswork
makingthingswork / validate-date.php
Last active November 19, 2020 14:34
Validate date
<?php
function valid_date(date,format='Y-m-d'){
d = DateTime::createFromFormat(format, date);
return d && (d->format(format) == date);
}
?>
@makingthingswork
makingthingswork / check-for-html.php
Last active November 19, 2020 14:35
Check for HTML
<?php
function is_html(string){
return (string != strip_tags(string)) ? true : false;
}
?>
@makingthingswork
makingthingswork / change-width-height.php
Last active November 19, 2020 14:36
Change width and height of HTML (string) element
<?php
function change_dimensions(str, width = '600', height = '450'){
return preg_replace(array('/width="\S+"/i', '/height="\S+"/i'),array(sprintf('width="%s"', width), sprintf('height="%s"', height)), str);
}
?>
@makingthingswork
makingthingswork / size.scss
Created August 21, 2019 13:38
Size shortcut mixin
//One value will create square as $height is set to $width
@mixin size($width, $height: $width) {
width: $width;
height: $height;
}
@makingthingswork
makingthingswork / check-ios.js
Created August 21, 2019 08:09
Check for iOS and add class to html
if(navigator.userAgent.toLowerCase().match(/(iphone|ipod|ipad)/)) { $('html').addClass('ios'); }
@makingthingswork
makingthingswork / console.js
Created August 21, 2019 08:07
Declare console variable to avoid error
var console = (window.console = window.console || {});