Skip to content

Instantly share code, notes, and snippets.

View mattidupre's full-sized avatar

Matti Dupre mattidupre

View GitHub Profile
@mattidupre
mattidupre / BEM Overview.md
Last active November 21, 2018 17:34
BEM Overview

Nutrien and BEM

Introduction

BEM stands for Block Element Modifier. Or, block__element--modifier. It's a syntax for combining similar blocks of tags together and making it easier to target them in your CSS. Most people hate it at first, but over time you will come to appreciate it. As with any methology, there are different ways of doing things. This document should therefore live on as working document to capture any decisions made on the topic moving forward.

But Why?

BEM is ugly. Very ugly. But the benefits far outweigh the drawbacks. BEM keeps your CSS organized and discourages you from writing declarations that overlap one another. Even more importantly, it lowers specificity for situations when that can be avoided. Lower specificity means less time spent in the document inspector trying to figure out which decorations are ruining your CSS groove.

@mattidupre
mattidupre / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mattidupre
mattidupre / gulpfile.js
Created May 7, 2015 23:56
My personal gulpfile using SASS, Browserify & Watchify, Jade, Retinze, and more...
/** package.json Dependencies
"devDependencies": {
"browserify": "^10.1.3",
"browserify-shim": "^3.8.6",
"dotenv": "^1.1.0",
"fs": "0.0.2",
"gulp": "^3.8.11",
"gulp-autoprefixer": "^2.2.0",
"gulp-bootlint": "^0.5.0",
"gulp-data": "^1.2.0",
// See http://www.es6fiddle.net/i0n48lf3/
/* BACKGROUND
Sometimes with Javascript it makes more sense to define a
function's arguments before calling / defining that function,
much like (my very limited understanding of) Ruby.
An example:

Keybase proof

I hereby claim:

  • I am mattidupre on github.
  • I am beluga (https://keybase.io/beluga) on keybase.
  • I have a public key whose fingerprint is 856B 3E3C 7DE9 40DF BEDF C917 9D7B EBBB 1DCD FB6B

To claim this, I am signing this object:

@mattidupre
mattidupre / plugin.jquery.cjs.js
Created April 14, 2014 18:59
Wrapper for converting jQuery plugins to CommonJS
(function (factory) {
if (typeof exports === 'object') {
// CommonJS
factory(require('./jquery'));
} else {
// Standard globals
factory(jQuery);
}
}(function ($) { // or (jQuery)
// Plugin code goes here.
@mattidupre
mattidupre / composeC()
Last active August 29, 2015 13:56
Combines functions into callback chain.
function compose() {
function c(fn, next) {
return function() {
var args = Array.prototype.slice.call(arguments, 0);
fn.apply(fn, [next].concat(args));
}
}
var fn = arguments[arguments.length-1];
for (var f=arguments.length-2; f>=0; f--) {
fn = c(arguments[f], fn);
@mattidupre
mattidupre / compose()
Last active August 29, 2015 13:56
Combines functions into single chain. Similar to lodash's _.compose, but updates the first argument to the return value of the previous function.
function compose() {
var functions = arguments;
return function() {
for (var n=0; n<functions.length; n++) {
var result = functions[n].apply(functions[n], arguments);
if (result === false) {
return false;
}
arguments[0] = result;
}
@mattidupre
mattidupre / backbone-loader.js
Created October 31, 2013 21:51
Backbone loader module that inserts plugins into the Backbone namespace and allows users to insert Model and Collection overrides, default functions. Also adds the ability to translate backbone sync() traffic bidirectionally, useful if your database schema changes but you don't want to rewrite your models.
define([
'backbone'
// add backbone extensions here
], function(Backbone) {
// Declare prototype Backbone.Model functions
var ModelP = {};
// Declare prototype Backbone.Collection functions
var CollectionP = {};
@mattidupre
mattidupre / sharepoint-menu.js
Created December 6, 2012 20:17
SharePoint Nested Menu Script
var initMenu = function () {
// Script compares document url with each menu url such that only those submenus that are children of the current page are toggled visible.
// Compares both subfolders (Pages/folder/item.aspx) and subsites (site/Pages/folder/item.aspx) with url.
// Hide all second-level menus.
$('#DhssZenNav li.static ul').attr('style', 'display: none;');
// Define regular expression.
var myRegExp = new RegExp('(?:/|.*?//?.*?/)(?:pub/|home/)*((?:.*?/)*).*?.aspx');