Skip to content

Instantly share code, notes, and snippets.

@paper_totals_by_client = Paper.past_pending
.joins(:client)
.group("clients.name")
.limit(5)
.count
# returns an object like the following:
# => {"Sample Business"=>1, "Sample Business 2"=>1, "Sample Business 3"=>1, "Sample Business 4"=>6}
@grumpit
grumpit / app.js
Created July 3, 2014 15:55
Uncaught TypeError: Cannot set property 'dataSourceBinding' of undefined when trying to set a model on Ember IndexRoute
MSSWApp = Ember.Application.create();
MSSWApp.Router.map(function() {
this.resource('categories', function() {
this.resource('category', { path: ':category_id' });
});
});
MSSWApp.IndexRoute = Ember.Route.extend({
model: function() {
@grumpit
grumpit / euler28.rb
Last active December 20, 2015 20:19
project euler 28
require 'benchmark'
def build_spiral(spiral_size)
total = 0
spiral_size.step(1, -2) do |i|
v1= i**2
i -= 1
total += i == 0 ? 1 : [v1, v1-i, v1-2*i, v1-3*i].inject{ |sum,x| sum + x }
end
total
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
@grumpit
grumpit / test_unit_test_should_raise_something
Created December 11, 2012 18:20
A Test::Unit::TestCase that passes - surprisingly.
require 'test/unit'
class SampleTest < Test::Unit::TestCase
def test_
end
end
# Returns the following
@grumpit
grumpit / fetchRelatedHack.js
Created July 29, 2012 02:50
Hack to allow Backbone.RelationalModel to fetchRelated() an associated collection as a whole in a single request
// Note: this means that on the collection that will be fetched, a truthy-returning fetchAsCollection() function
// must be present
fetchRelated: function( key, options, update ) {
options || ( options = {} );
var setUrl,
requests = [],
rel = this.getRelation( key ),
/*
If you add something like this pseudoCode, it will handle cases where we want to fetch a collection
@grumpit
grumpit / exercise for JS Master Class
Created May 25, 2012 17:10
Exercise for JS Master Class
var Person = function(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
@grumpit
grumpit / closures exercise
Created May 24, 2012 19:08
JSMasterClass Exercise
(function(countdown, container){
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
index--;