Skip to content

Instantly share code, notes, and snippets.

@gerardvcruz
gerardvcruz / fruits.rb
Last active May 9, 2018 08:45
Fruits!
require 'rspec'
# The goal is to make the tests pass
# Get the cheapest price for each seller.
# Seller x the priority seller.
# returs a hash containing fruits,
# sub keys under fruits are prices
# and fruit "keys"
def fruits_prices(sellers)
// <input ng-model="foobar">
// $scope.foobar is an object with attribute 'baz'
$scope.foo = _.map($scope.barArray, function(bar) {
if(bar.baz === $scope.foobar.baz) {
return bar;
}
});
// after uglifying, i cannot access $scope.foobar.baz in the _.map anymore
# q can be unlimited length
# one var only
# each element is a single digit integer
class SingleVarQ
def initialize(start)
@q = start
end
def queue
@gerardvcruz
gerardvcruz / child.rb
Created March 12, 2015 07:07
hey everyone, I'm dealing with multiple child objects under 1 parent object (one to many relationship) right now in rails and I was wondering how you guys will handle the updating the parent object and the multiple child objects. this is what i'm implementing right now:
class Child < ActiveRecord::Base
belongs_to :parent
def self.update_info
self.with_lock
if true
# succesful
true
else
# fail
<% form_for @object do |f| %>
<%= f.label :foo %>
<%= f.text_field :foo %>
<% f.fields_for :bar do |ff| %>
<%= ff.radio_button :some_attr, 1 %>
<%= ff.label :some_attr %>
<%= ff.radio_button :some_attr, 2 %>
<%= ff.label :some_attr %>
<% end %>