Skip to content

Instantly share code, notes, and snippets.

View danmartens's full-sized avatar
✌️

Dan Martens danmartens

✌️
View GitHub Profile
@danmartens
danmartens / arel_timezone_offset.rb
Created April 12, 2014 14:28
Arel Timezone Offset Predication
module Arel
module Predications
def tz_offset(offset)
Nodes::InfixOperation.new('AT TIME ZONE INTERVAL', self, offset)
end
end
end
@danmartens
danmartens / ui-image.js
Last active August 29, 2015 13:58
AngularJS Responsive Image Tag
/***
* Example:
*
* <span ui-image
* load-image="true"
* srcset="[
* [image.large_mobile, '650w 1x'],
* [image.large_mobile_2x, '650w 2x'],
* [image.large, '1x'],
* [image.large_2x, '2x']
@danmartens
danmartens / responsive_image_helper.rb
Last active August 29, 2015 13:58
Picturefill Responsive Image Tag Rails Helper
###
# Example:
#
# module ProductImageHelper
# def product_image_tag(product, options={})
# image = product.images.first.attachment
#
# image_queries = [
# {
# src: image.url(:large_mobile_2x),
@danmartens
danmartens / ember_helper.rb
Created April 2, 2014 14:25
Ember Template Helper
###
# <%= ember_template 'greeting' do %>
# Hello {{name}}!
# <% end %>
###
module EmberHelper
include ActionView::Helpers::CaptureHelper
def ember_template(name, &block)
@danmartens
danmartens / give-up.sh
Last active December 27, 2015 17:58
When all else fails...
# curl -L https://gist.github.com/danmartens/7365748/raw/give-up.sh | sh
# Please make sure Xcode is up to date and you've agreed to the license!
echo_purple(){
echo "\n\033[45m$1\033[0m\n"
}
clear
Ember.Handlebars.registerBoundHelper 'pluralize', (number, singular, plural) ->
unless Ember.typeOf(plural) is 'string'
plural = "#{singular}s"
return if number is 1 then singular else plural
@danmartens
danmartens / jquery_plugin.coffee
Last active December 20, 2015 11:19
jQuery plugin pattern that attaches a class instance to the element. Inspired by http://coding.smashingmagazine.com/2011/10/11/essential-jquery-plugin-patterns.
(($) ->
pluginName = 'pluginName'
defaults = {
prop: 'value'
}
class Plugin
constructor: (element, options) ->
@el = element; @$el = $(element)
@danmartens
danmartens / CD to Project
Last active December 14, 2015 11:59
ZSH Functions
c() { cd ~/Projects/$1; }
_c() { _files -W ~/Projects -/; }
compdef _c c
alias c='nocorrect c'
@danmartens
danmartens / capybara_javascript_helpers.rb
Last active December 11, 2015 06:39
Capybara JavaScript Helpers
# Example:
#
# it "should alert me" do
# stub_browser_alert
#
# visit "/"
#
# wait_until { browser_alert_messages.count > 0 }
#
# browser_alert_messages.last.should eq("Hello World!")
@danmartens
danmartens / backbone.collection_view.js
Last active December 11, 2015 02:28
A Backbone.View for displaying a Backbone.Collection.
/*
* Example:
*
* ListView = Backbone.CollectionView.extend({
* tagName: 'ul'
* itemView: Backbone.View.extend({
* tagName: 'li',
* template: _.template('<%= item.content %>'),
*
* initialize: function() {