Skip to content

Instantly share code, notes, and snippets.

View paulhhowells's full-sized avatar

Paul H Howells paulhhowells

  • Shepperton, U.K.
View GitHub Profile
module.exports = {
"extends": ["eslint:recommended"],
"env": {
"browser": true,
"es6": false,
"node": true
},
"globals": {
"jQuery": true,
"$": true,
@paulhhowells
paulhhowells / reserved words.md
Last active August 29, 2015 13:57
Reserved Words in Javascript

reserved words

break
case
catch
continue
debugger
default
delete

do

@paulhhowells
paulhhowells / style-guide.md
Last active December 20, 2015 21:49
style guide

style guide

css (& smacss)

file structure

organise Less files into directories:

@paulhhowells
paulhhowells / breakpoint-mixin-wrapper.less
Last active December 20, 2015 15:38
Use a SMACSS style CSS Module as a Less Mixin within a breakpoint as well as on it’s own (as a standalone CSS Module). Uses the (SMACSS derived) Unit grid system style of writing class names with breakpoints. This pattern will enable you to keep your Less DRY for this CSS module. Note that the example Module has classes (i.e. .x-1, .x-2) that ar…
.inner(...) {
/* INNER */
}
.inner(a) {
/* type A */
.x-1 {float: left;}
.x-2 {float: right;}
}
.inner(b) {
/* type B */
@paulhhowells
paulhhowells / inhouse template.php
Last active December 19, 2015 16:19
inhouse theme template.php - (work in progress)
<?php
/* C U S T O M F U N C T I O N S */
/**
* search an array recursively to find
* the first instance of a key and return its value
*
* useful when you do not know the location of a key nested (only once) in a multidimensional array
*
@paulhhowells
paulhhowells / metamorphosis pattern .js
Last active December 16, 2015 12:39
Douglas Crockford’s Module pattern, but it starts (and finishes) as an object rather than a function. A publicly accessible object metamorphoses into an object with public methods and variables, and private methods and variables.
metamorphosis = {
defaults : {
thing : 4
},
init : function (options) {
var
the = this,
o, // private object
p; // public object
@paulhhowells
paulhhowells / rounding functions .js
Last active December 16, 2015 11:49
rounding functions
phh = phh || {};
phh.round = function (n) {
return ~~((n >= 0 ? n : -n) + 0.5);
};
phh.ceil = function (n) {
// faster than Math.ceil, but only behaves the same when testing positive numbers
// http://jsperf.com/math-ceil/4
@paulhhowells
paulhhowells / memory leaks .js
Last active May 25, 2022 08:33
avoid memory leaks with closures. google javascript style guide.
// from google javascript style guide:
// One thing to keep in mind, however, is that a closure keeps a pointer to its enclosing scope. As a
// result, attaching a closure to a DOM element can create a circular reference and thus, a memory leak.
// For example, in the following code:
// Leaky example
function foo (element, a, b) {
element.onclick = function() {
// uses a and b
// this func keeps a pointer to foo, its enclosing scope
@paulhhowells
paulhhowells / cookie functions .js
Last active December 16, 2015 11:49
Cookie handling methods. Copied from code written by PPK : http://www.quirksmode.org
@paulhhowells
paulhhowells / url hash & query string .js
Last active December 16, 2015 11:49
get hash and query string from url
phh = phh || {};
(function ($) {
$(function () {
phh.url.init();
});
phh.url = (function () {
// v 1.3
// runs before dom ready or window loaded