Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / get_svg_images.rb
Last active December 18, 2015 18:10
Get a dynamic list of .svg images. Useful for CSS masks, without having to manually maintain a list of .svg icons.
# Custom Sass function to get a list of images in a directory.
# https://gist.github.com/brianmcallister/5824102
#
# path - Directory in which to get svg images. Defaults to a blank string.
#
# Returns a list of images.
def get_svg_images(path = Sass::Script::String.new(''))
assert_type path, :String
files = []
@brianmcallister
brianmcallister / 1-variables.scss
Created June 7, 2013 02:22
Sometimes you want to set some CSS properties based on a class set high up in your DOM. JavaScript makes this fairly easy, but let's do it with Sass instead.
$states: state1 #00adee, state2 #ffc10e, state3 #ec145a;
$color_selectors: null;
@brianmcallister
brianmcallister / replace-text-with-svg.scss
Last active December 14, 2015 09:28
Sass mixin to replace text with an svg background image. Requires the existence of a png fallback, which is what you should be doing anyway.
/*
Replace text with svg, use a png fallback.
https://gist.github.com/brianmcallister/5065262
$img - Image name to use, no extension.
*/
@mixin replace-text-with-svg($img) {
@extend %hide-text;
$png: '#{$img}.png';
@brianmcallister
brianmcallister / cache.coffee
Last active December 14, 2015 00:39
Wrapper around localStorage to do time based caching of data.
# Class for using localStorage to cache data for a set amount of time.
# https://gist.github.com/brianmcallister/5000368
#
# name - Name for this cache.
#
# Examples
#
# cache = new Cache('my-cache').set 'my-data', {data: 'hats'}, 120
class Cache
# Private: Just a function that returns null.
@brianmcallister
brianmcallister / archive.sh
Last active December 11, 2015 18:08
Bash script for archiving project directories. Learning bash, so this is very much a work in progress.
#!/bin/bash
# Archive old projects
#
# - Create a tar.gz file out of a folder
dir=~/Archive
# Echo a message. TODO - Colors.
function msg() {
echo "> $*" >&2
@brianmcallister
brianmcallister / shim.js
Last active December 10, 2015 13:59
Transition end event name shim for Modernizr.
// Transition end event shim.
// https://gist.github.com/brianmcallister/4444457
this.Modernizr.transEndEventName = {
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition': 'transitionend',
'transition': 'transitionend'
}[this.Modernizr.prefixed('transition')];
@brianmcallister
brianmcallister / location.rb
Last active December 9, 2015 22:59
Wrapper around Ruby's Array#index method.
# Wrapper around Ruby's Array#index method.
# https://gist.github.com/brianmcallister/4341575
#
# value - The value in the list to search for.
# list - The list to search through.
#
# Examples
#
# $list: a b c;
# @debug location(b, $list);