Skip to content

Instantly share code, notes, and snippets.

View tomfordweb's full-sized avatar
🏠
Working from home

Tom Ford tomfordweb

🏠
Working from home
View GitHub Profile
@tomfordweb
tomfordweb / formatcurrency.js
Created February 23, 2018 19:42
JS Money Format
// stolen from https://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-dollars-currency-string-in-javascript
Number.prototype.formatMoney = function(c, d = '.', t = ','){
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
j = (j = i.length) > 3 ? j % 3 : 0;
@tomfordweb
tomfordweb / gallery.html
Last active December 14, 2017 23:22
Fix aspect ratio of images by zooming. This will "crop" your image.
@tomfordweb
tomfordweb / full-width.scss
Created December 4, 2017 16:06
Sassy Full Width Bars
// taken from
// https://css-tricks.com/full-browser-width-bars/
@mixin full-width-bar($background) {
position: relative; /* for the child pseudo-elements */
/* negative offset = section padding */
margin: 0 -30px;
/* add back section padding value */
padding: 0.25rem 30px;
background: $background;
@tomfordweb
tomfordweb / wp-post_meta-orphans.sql
Created December 2, 2017 18:09
WordPress orphaned post meta
DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
@tomfordweb
tomfordweb / WP-missing-featured.sql
Last active January 3, 2019 19:18
Select All posts that are missing featured image
@tomfordweb
tomfordweb / no-more-duplicates.sql
Created December 2, 2017 17:44
Delete duplicate posts for WP, but can be used for most anything. Worked very quickly on a 60k row wp_posts table.
DELETE FROM wp_posts
WHERE id IN (SELECT *
FROM (SELECT id FROM wp_posts
GROUP BY post_title HAVING (COUNT(*) > 1)
) AS A
);
@tomfordweb
tomfordweb / SPEAK-MURICAN.sql
Last active December 14, 2017 23:28
Replace non-english characters. Back up your database and make sure you want to use every query here.
# Good for fixin urls
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'.',' ');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,' ','-');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'--','-');
UPDATE TABLE_NAME SET COLUMN = LOWER(COLUMN);
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Š','S');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'š','s');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ð','Dj');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ž','Z');
@tomfordweb
tomfordweb / csc.php
Last active July 17, 2017 13:24
User Defined Shortcodes in WP, uses ACF repeater and options plugin, but can be configured to run on anything
<?php
/**
* Adds "user defined" shortcodes via ACF options and repeater plugins
*/
function addUserDefinedShortCodes()
{
if( have_rows('codes','option') ):
// loop through the rows of data
@tomfordweb
tomfordweb / index.js
Created June 7, 2017 15:34
JQuery + Bootstrap 3 - Responsive Breakpoint body classes
function addResponsivePixelToBody()
{
$('body').append('<div id="xs-res" class="hidden-sm hidden-md hidden-lg"></div><div id="small-res" class="hidden-md hidden-xs hidden-lg"></div><div id="medium-res" class="hidden-sm hidden-xs hidden-lg"></div><div id="large-res" class="hidden-sm hidden-xs hidden-md"></div><div class="col-sm-12 col-md-4 text-center">');
}
function responsiveBreakpoints()
{
var xs = $('#xs-res');
var small = $('#small-res');
var med = $('#medium-res');
var large = $('#large-res');
@tomfordweb
tomfordweb / wp-single-level-nav.php
Created June 1, 2017 15:59
WP Single Level Menu Helper
<?php
class SingleLevelNav
{
public $location;
function __construct($location)
{
$this->location = $location;
add_filter( 'wp_nav_menu_args', [$this, 'forceSingleLevelNav'], 10);