Skip to content

Instantly share code, notes, and snippets.

View danmartens's full-sized avatar
✌️

Dan Martens danmartens

✌️
View GitHub Profile
(function( $ ){
$.fn.styleCheckbox = function() {
return this.each(function() {
var $custom, $label, toggleCheckbox, $input = $(this);
$custom = $('<a class="checkbox" href="#"></a>');
toggleCheckbox = function() {
@danmartens
danmartens / d3.selection_extensions.coffee
Created April 29, 2012 19:32
D3.js Selection Extensions
d3.selection::attrs = (attrs) ->
for key, value of attrs
@attr(key, value)
return this
d3.selection::addClass = (name) ->
@classed(name, true)
return this
@danmartens
danmartens / ember.array_extensions.js.coffee
Created June 8, 2012 19:21
Ember.js Array Extensions
# Sorts an array based on a property of each object within the array
#
# Examples:
#
# [Em.Object.create(a: 1), Em.Object.create(a: 5), Em.Object.create(a: 3)].sortProperty('a')
# > [{a: 1}, {a: 3}, {a: 5}]
#
# As a computed property:
#
# AC = Em.ArrayController.extend
@danmartens
danmartens / Ember.Resource.find.js
Created July 22, 2012 17:01
Ember.Resource::find
var pathToObject = function(path) {
var i, parent, part, parts, _len;
parent = window;
parts = path.split('.');
for (i = 0, _len = parts.length; i < _len; i++) {
part = parts[i];
parent = parent[part] || (parent[part] = {});
}
@danmartens
danmartens / fixit.plugin.zsh
Created August 28, 2012 18:22
Attempts to fix Rails applications
# Only the professor can fix it
fixit() {
clear;
echo -e '\x1B[30;45m'"\n\033[1m Bundle installing... \033[0m\n";
bundle install;
echo -e '\x1B[30;45m'"\n\033[1m Migrating database... \033[0m\n";
bundle exec rake db:migrate;
hasPushState = !!(window.history && window.history.pushState)
window.FTW or= {}
class FTW.Router
constructor: (@routes) ->
if hasPushState
window.onpopstate = (e) =>
@navigate(@getURI())
@danmartens
danmartens / README.md
Created September 20, 2012 14:39
SCSS Grid

How to use

1/3, 2/3 columns

<div class="row">
  <div class="column width-2"></div>
  <div class="column width-4"></div>
</div>
@danmartens
danmartens / format_money.coffee
Created November 19, 2012 19:19
Format Money in Coffeescript
# Inspired by http://stackoverflow.com/a/149099/1649199
Number::formatMoney = (t=',', d='.', c='$') ->
n = this
s = if n < 0 then "-#{c}" else c
i = Math.abs(n).toFixed(2)
j = (if (j = i.length) > 3 then j % 3 else 0)
s += i.substr(0, j) + t if j
return s + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
@danmartens
danmartens / 99_designs.rb
Created November 19, 2012 22:34
Mechanize - Submit to 99 Designs
require 'mechanize'
@agent = Mechanize.new
@agent.user_agent_alias = 'Mac Safari'
def sign_in(email, password)
page = @agent.get "https://99designs.com/login"
form = page.forms.first
form.field_with(name: 'email').value = email
form.field_with(name: 'password').value = password
@danmartens
danmartens / parse_hash.js
Created December 6, 2012 19:55
Parses location.hash into an Object
window.parseHash = function() {
var parsed = {};
var pairs = window.location.hash.replace('#', '').split('&');
pairs.forEach(function(pair) {
parsed[pair.split('=')[0]] = (parseInt(pair.split('=')[1], 10) || pair.split('=')[1]);
});
return parsed;
};