Skip to content

Instantly share code, notes, and snippets.

View tomblanchard's full-sized avatar

Tom Blanchard tomblanchard

View GitHub Profile

Main Title

I have a utility class such as:

.mb {
  margin-bottom: 20px;
}
@tomblanchard
tomblanchard / native-js-api-pollyfills.js
Created June 9, 2014 18:43
Native JS API pollyfills
/**
`classList` pollyfill:
https://github.com/remy/polyfills/blob/master/classList.js
*/
!function(){function e(a){this.el=a;for(var c=a.className.replace(/^\s+|\s+$/g,"").split(/\s+/),d=0;d<c.length;d++)b.call(this,c[d])}function f(a,b,c){Object.defineProperty?Object.defineProperty(a,b,{get:c}):a.__defineGetter__(b,c)}if(!("undefined"==typeof window.Element||"classList"in document.documentElement)){var a=Array.prototype,b=a.push,c=a.splice,d=a.join;e.prototype={add:function(a){this.contains(a)||(b.call(this,a),this.el.className=this.toString())},contains:function(a){return-1!=this.el.className.indexOf(a)},item:function(a){return this[a]||null},remove:function(a){if(this.contains(a)){for(var b=0;b<this.length&&this[b]!=a;b++);c.call(this,b,1),this.el.className=this.toString()}},toString:function(){return d.call(this," ")},toggle:function(a){return this.contains(a)?this.remove(a):this.add(a),this.contains(a)}},window.DOMTokenList=e,f(Element.prototype,"classList",function(){return new e(this)})}}();
/**
@tomblanchard
tomblanchard / array-object-for-loop.js
Last active August 29, 2015 14:01
Array of objects `for` loop with repaint performance in mind, mostly for use in fetching and displaying data from external JSON APIs.
var data = [
{
id: 1,
name: 'One',
image: 'http://image-1.jpg'
},
{
id: 2,
name: 'Two',
image: 'http://image-2.jpg'
@tomblanchard
tomblanchard / mini-modernizr.html
Created April 25, 2014 14:09
Mini Modernizr: I only ever use Modernizr mostly to check for JS and / or touch screen devices. This tiny piece of code will replace the classes which are on the `<html>` element `no-js` with `js` and `no-touch` with `touch`.
<script>!function(a,b){"use strict";b.documentElement.className=b.documentElement.className.replace("no-js","js"),("ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch)&&(document.documentElement.className=document.documentElement.className.replace("no-touch","touch"))}(window,document);</script>
@tomblanchard
tomblanchard / bigcartel-feed.js
Last active March 6, 2018 12:29
BigCartel Feed.
$.getJSON('http://api.bigcartel.com/USERNAME/products.json?limit=5&callback=?', function(data) {
$.each(data, function(i, obj) {
$('\
<a href="http://USERNAME.bigcartel.com' + obj.url + '">' +
obj.name +
'$' + parseFloat(obj.price, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,').toString() +
'<img width="100" src="' + obj.images[0].url + '" alt="">' +
'</a>'
).appendTo('.products');
@tomblanchard
tomblanchard / code-comments-README.md
Last active August 29, 2015 13:55
Code comments.

This is how I handle my code comments, there are 2 types:

  • Section header (with optional additional comment(s))
  • Regular comment(s)

All comments are limited to 80 characters per line with padding on each horizontal side consisting of two spaces.

[sendmail]
smtp_server = mail.tomblanchard.co.uk
smtp_port = 26
smtp_ssl = none
error_logfile = error.log
@tomblanchard
tomblanchard / border-box.css
Created October 31, 2013 19:44
Border box.
.border-box,
.border-box:before,
.border-box:after,
.border-box *,
.border-box *:before,
.border-box *:after {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
@tomblanchard
tomblanchard / wp-snippets-child-theme.css
Last active December 25, 2015 11:09
Regular WP snippets I use.
/***********************************************************************************
THEME NAME: Parent Theme - Child
***********************************************************************************
Template: parent-theme
Author: Tom Blanchard
Author URI: http://tomblanchard.co.uk
Version: 1.0
**********************************************************************************/
@tomblanchard
tomblanchard / php-ajax-form.html
Last active December 24, 2015 13:09
PHP AJAX Form
<form class="contact-form" method="post" action="">
<ul class="form-fields">
<li>
<label>Your Name</label>
<input class="text-input" type="text" name="name" required value="TEST NAME">
</li>
<li>
<label>Your Email</label>
<input class="text-input" type="email" name="email" required value="email@email.com">
</li>