Skip to content

Instantly share code, notes, and snippets.

View patrickberkeley's full-sized avatar

Patrick Berkeley patrickberkeley

View GitHub Profile

This grouped bar chart is constructed from a CSV file storing the populations of different states by age group. The chart employs conventional margins and a number of D3 features:

@patrickberkeley
patrickberkeley / test_helper.coffee
Created March 7, 2014 21:45
Ember test helper for bootstrapping qunit tests
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>')
App.rootElement = '#ember-testing'
App.ApplicationAdapter = DS.FixtureAdapter.extend()
App.setupForTesting()
App.injectTestHelpers()
window.exists = (selector) ->
@patrickberkeley
patrickberkeley / mock_request.coffee
Last active August 29, 2015 13:57
Wrapper for mocking AJAX requests with Mockjax - https://github.com/appendto/jquery-mockjax
# Wrapper for mocking AJAX requests with Mockjax - https://github.com/appendto/jquery-mockjax
#
# Arguments:
#
# url - String, endpoint for request you want to capture
# response - Object, response you expect to be returned from the endpoint
# opts - Object (optional)
# opts.type - String, the HTTP request type. Default 'GET'
# opts.status - Integer, the HTTP response status code. Default 200
# opts.data - Object, data object passed with request. Default null
this.get('controller.target.location.location.pathname');
@patrickberkeley
patrickberkeley / application.js
Created March 13, 2014 19:21
Set the current path as a class on ember's application view.
App.ApplicationView = Ember.View.extend({
classNames: ['app'], // Static classes here.
classNameBindings: ['classForPath'], // Your dynamic path here.
classForPath: (function() {
var currentPath = this.get('controller.currentPath') || '';
currentPath = Ember.String.decamelize(currentPath);
currentPath = currentPath.split('.').join('-');
return currentPath;
}).property('controller.currentPath')
});
<html>
<head>
<title>test</title>
</head>
<body>
<h1>testing gist</h1>
<script src="http://gist.github.com/3806.js"></script>
</body>
</html>
Inflector.inflections do |inflect|
inflect.plural 'still life'
inflect.singular 'still lives'
end
def add_to_cart
@cart = find_cart
product = Product.find(params[:id])
quantity = params[:quantity]
quantity ||= 1
if quantity.to_i > product.quantity.to_i
logger.info "This product only has #{product.quantity.to_i} remaining."
render :nothing => true, :status => 400 and return
else
@data={:last_order_list_view=>"All", :order_id=>nil, :cart=>#<Cart:0x250c27c @items=[#<OrderLineItem id: nil, item_id: 2, order_id: 0, quantity: 1, unit_price: 95.0, name: "test">], @shipping_cost=0.0, @tax=0.0, @total=0.0>, :user=>1, :return_to=>nil, :product_id=>"2", "flash"=>{}}