Skip to content

Instantly share code, notes, and snippets.

@brianmcallister
brianmcallister / breakpoints.json
Last active August 29, 2015 13:56
Read a JSON file containing breakpoints, and return a Sass list.
{
"desktop": {
"min": 801
},
"tablet": {
"min": 481,
"max": 800
},
"phone": {
"max": 480
@brianmcallister
brianmcallister / events.coffee
Created March 19, 2014 14:31
Backbone base class to inherit events all the way up the prototype chain. Obviously this only works when using CoffeeScript classes due to the use of __super__.
class BaseView extends Backbone.View
# Public: Events.
events: {}
# Public: Constructor.
#
# Returns this.
constructor: ->
# Inherit events.
cls = this
@brianmcallister
brianmcallister / map-me.scss
Created July 24, 2014 15:18 — forked from jackie/gist:a65bb078c8c9eb4bbb57
map-me: A way to extract values from a nested map.
// Extract values from a nested map.
// Original: https://gist.github.com/jackie/a65bb078c8c9eb4bbb57
//
// $map - Map from which to extract the value.
// $keys - List of keys.
//
// Examples
//
// $map: (one: (two: val: 'value'));
// map-me($map, one two val);
@brianmcallister
brianmcallister / params.coffee
Created September 12, 2014 15:11
Parse query parameters.
# Parse the query string params.
# https://gist.github.com/brianmcallister/94d89b3c50b2b9e98f6d
#
# Examples
#
# If the query string is:
# test=test&foo&a=truee&bool=false&num=10
#
# parseQueryParams()
# #=> {"test": "test", "foo": "", "a": "truee", "bool": false, "num": 10}
@brianmcallister
brianmcallister / highlight.coffee
Last active August 29, 2015 14:16
Highlight words in text. Still need to remove the underscore dependency.
# Private: Highlight individual words within the message text.
#
# text - Text to format.
# words - Array of words to highlight.
#
# Returns the formatted text.
highlightWords = (text, words = []) ->
return text if words.length is 0
# Create a DOM element to contain the text so we can detect and handle
@brianmcallister
brianmcallister / natural-sort.coffee
Last active August 29, 2015 14:20
CoffeeScript natural sort. Ported from Dave Koelle's Alphanum Algorithm.
# Public: Natural sort an array.
# https://gist.github.com/brianmcallister/f0e77c185f4a0d6f7172
# Ported to CoffeeScript from: http://www.davekoelle.com/files/alphanum.js
# See: http://www.davekoelle.com/alphanum.html
#
# This function has been modified to support passing in an array as an
# argument, as opposed to attaching this function to the Array prototype.
#
# array - Array to natural sort.
#
@brianmcallister
brianmcallister / html5_placeholder_polyfill.js
Created February 10, 2012 19:23
HTML5 Placeholder polyfill
/*jslint devel: true, browser: true, indent: 2, nomen: true */
/*global jQuery, Modernizr */
// Load a polyfil for placeholder support
(function ($, Modernizr) {
'use strict';
if (!Modernizr.input.placeholder) {
var Actions = {
focusInput: function () {
@brianmcallister
brianmcallister / apply-pointer.scss
Last active October 6, 2015 03:58
Apply pointer mixin. Applies CSS3 arrows to an element.
/*
Apply pointer mixin. Uses a CSS3 pseudo element to apply a triangle.
https://gist.github.com/brianmcallister/2932442
@param {String} [$side] Which side the pointer should stick out from. Defaults to top.
@param {String} [$size] Size of the pointer. Expects units, ex: 5px. Defaults to 5px.
@param {String} [$color] Color of the pointer. Defaults to white.
@param {String} [$type] Which kind of triange to make. Defaults to equilateral.
@param {Boolean} [$clockwise] If using a right triange, the direction the triange should be rotated.
@param {String} [$element] Which type of psuedo element to be used. Defaults to :after.
@brianmcallister
brianmcallister / replace-text-with-inline.scss
Created July 5, 2012 14:50
Replace text with an inline image. Exactly the same as replace-text-with-dimensions, but inline images.
@mixin replace-text-with-inline($img) {
@include hide-text;
width: image-width($img);
height: image-height($img);
background: center center no-repeat inline-image($img);
}
@brianmcallister
brianmcallister / retina-image.scss
Created July 5, 2012 14:51
Set a background image sized for retina screens, with an option to use the image url or an inline image.
/*
Set a background image sized for retina screens, with an option to use the image url or an inline image.
@param {String} $image Image to use.
@param {String} [$type] Type of image url to use. Default to an inline image.
*/
@mixin retina-image($image, $type: 'inline') {
@include hide-text;
@if $type != 'inline' and $type != 'url' {
@warn 'Unknown usage type. Falling back to "url"';