Skip to content

Instantly share code, notes, and snippets.

View mrgenixus's full-sized avatar

Ben West mrgenixus

View GitHub Profile
@mrgenixus
mrgenixus / groups.js
Last active March 3, 2016 02:36
group ingredients by stemmed_title
function group_or_item(values){
return (values.length > 1 ? 'group' : 'item');
}
function get_group_values(key) {
return groups[key];
}
function getFrom(list) {
return function(key) {
@mrgenixus
mrgenixus / my_profiler.rb
Last active March 3, 2016 00:07
Peak Memory Profiler
class MyProfiler
def self.profile
p = Profiler.new
p.event "Begin"
yield p
p.event "End"
p
end
@mrgenixus
mrgenixus / acceptance.rb
Last active February 29, 2016 22:03
Acceptance
class Acceptance
include ActiveModel::Model
include ActiveModel::Validations
extend ActiveModel::Naming
class Type < Struct.new(:list?, :all?, :individual?); end
attr_accessor :invitation_id
attr_accessor :invitation_ids
attr_accessor :user_id
https://plus.google.com/hangouts/_/calendar/ZGF2aWRqYmV2ZXJpZGdlQGdtYWlsLmNvbQ.0o6bh4pin9d2d5dol1n35khrcc?authuser=1
@mrgenixus
mrgenixus / active_model_lint.rb
Created February 26, 2016 14:26 — forked from dmitriy-kiriyenko/active_model_lint.rb
ActiveModel lint tests for rspec
# put the file into spec/support
shared_examples_for "ActiveModel" do
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
example m.gsub('_',' ') do
send m
end
end
@mrgenixus
mrgenixus / alternative store_store.js
Last active February 24, 2016 21:06
Proposed base store
export default FluxStore.extend({
model: 'store',
events: {
"ASSOCIATE_STORE": 'associate_store'
},
create(payload) {
return Store.create(payload.data)
},
@mrgenixus
mrgenixus / shopping_list_item_mixin.rb
Last active February 17, 2016 04:30
Extracted from ShoppingList#list_items as refactor
scope :without_removed, -> { where(arel_table[:removed].eq(nil).or(arel_table[:removed].eq(0))) }
scope :only_removed, -> { where(arel_table[:removed].not_eq(nil)).where(arel_table[:removed].not_eq(0)) }
def self.date_range start_date, end_date
includes(:event).
where(Event.arel_table[:event].gteq(start_date)).
where(Event.arel_table[:event].lteq(end_date))
end
@mrgenixus
mrgenixus / evaluate.js
Created December 8, 2015 04:20
survey_response_requirements
var survey_responses = [
{
eyes: {
color: 'blue'
},
flavors: {
favorite: 'vanilla'
}
}
var Backbone = require('backbone');
var _ = require('underscore');
var MVCObject = function MVCObject() {
if(_.isFunction(this.initialize)) {
this.initialize.apply(this, arguments);
}
};
_.extend(MVCObject.prototype, Backbone.Events);
@mrgenixus
mrgenixus / Gemfile
Last active October 28, 2015 22:56
quasi-inherited hashes
# A sample Gemfile
source "https://rubygems.org"
gem "pry"