Skip to content

Instantly share code, notes, and snippets.

View mikefowler's full-sized avatar

Mike Fowler mikefowler

View GitHub Profile
@mikefowler
mikefowler / .bash_profile
Last active December 17, 2015 03:09
Do you clone a lot of Github repositories from Terminal? If you do, you'll probably dig this.
# USAGE
#
# > clone chriseppstein/compass
#
# Cloning into 'compass'...
githubclone() {
git clone [email protected]:$1.git;
}
@mikefowler
mikefowler / StartView.js.coffee
Created December 28, 2012 02:56
Defining RequireJS modules + Coffeescript classes with the RequireJS sugar syntax. More detail here: http://requirejs.org/docs/whyamd.html#sugar
define (require) ->
$ = require 'jquery'
_ = require 'underscore'
Backbone = require 'backbone'
Handlebars = require 'handlebars'
View = require 'lib/view'
startTemplate = require 'text!templates/start.html'
class StartView extends View
getRandomColor: ->
number = Math.floor(Math.random() * (3 - 1 + 1)) + 1
switch number
when 1 then "#983a30"
when 2 then "#187598"
# why not
getRandomColor: -> ["#983a30", "#187598"][Math.ceil(Math.random() * 3)]
@mikefowler
mikefowler / LinkValidation.js.coffee
Created December 7, 2012 23:23
Link validation class
#
# Coffeescript + Underscore syntactic sugar makes this so gracefully concise.
#
class LinkValidation
constructor: ->
@VALID_SERVICES = [
"flickr.com\/photos\/[a-z0-9_-]+\/(\d+)"
@mikefowler
mikefowler / mq.scss
Created October 3, 2012 18:40
Retina Media Queries for Sass
// Based on Chris' post here: https://gist.github.com/3828790
@mixin respond-to($size) {
// Small
@if $size == "small" {
@media only screen and (min-width: 320px) {
@content;
}
@mikefowler
mikefowler / retina.scss
Created October 2, 2012 15:17
Compass mixin for handling retina images.
/**
* Bear in mind: this is NOT a way to address
* issues with bandwidth and sending large
* images to a mobile browser.
*
* For a great discussion of that, check out this A List Apart
* article by Dave Rupert: http://bit.ly/QGfJk4
*
* The media query is based on the snippet recently posted by Chris
* Coyier on CSS Tricks: http://bit.ly/QGg71V
@mikefowler
mikefowler / index.html
Created September 28, 2012 17:48
Constraining index when selecting DOM elements.
<!--
This is a simple way to constrain an index to a range. A good use case for this is
selecting DOM elements and then getting the element on a given index in that selection.
The code in getIndexInSelection() will constrain the index to the range of elements available,
choosing either the highest or lowest index if the requested index is out of range.
-->
<div id="container">
<section>...</section>
@mikefowler
mikefowler / _base.scss
Created September 25, 2012 14:16
Flexible Backgrounds with Sass and Compass
/**
* Our theme base.
*
* We shouldn't have to modify this to create a new theme.
*/
@import 'compass/css3/images';
$page-fill: #f1f1f1 !default;
@mikefowler
mikefowler / nth.scss
Created September 24, 2012 14:47
Handy nth-child Recipes
// Odd or Even
&:nth-child(even/odd) { }
// Every third item
&:nth-child(3n) {}
// Every third item, starting with the first
&:nth-child(3n-5) { }
// Every fourth item
@mikefowler
mikefowler / index.html
Created September 12, 2012 02:49
Easy to maintain media query fallbacks for <=IE8
<!doctype html>
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--><html class="no-js" lang="en"> <!--<![endif]-->
<head>
<title>Example</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">