Skip to content

Instantly share code, notes, and snippets.

View tdouce's full-sized avatar

Travis Douce tdouce

View GitHub Profile
@tdouce
tdouce / gist:2044492
Created March 15, 2012 14:32
Postal Code not in database
# Get the 2nd project's project_item
(rdb:5) p self.project.project_items[1]
#<ProjectItem id: 8, project_id: 2, product_id: 67, quantity: 1, unit_price: #<BigDecimal:10bde4cc8,'0.25E2',9(18)>, postal_code_of_manufacture: "29729", params: nil, postal_code_of_fabrication: nil>
# Find out how many possible manufacturing locations there are for this project_item
(rdb:5) p self.project.project_items[1].product.product_features_for_type('l_m').size
7
# Get all the possible manufacturing locations for this project_item
(rdb:5) p self.project.project_items[1].product.product_features_for_type('l_m')
@tdouce
tdouce / Distance from project to product manufacturers
Created March 13, 2012 18:36
Retrieve distance from project location to product manufacturers
# Get all lookup_keys for a product
?> project2.project_items[1].product.product_features.map {|pf| [pf.product_feature_type.lookup_key, pf.product_feature_type.description] }
# pretty print
?> project2.project_items[1].product.product_features.map {|pf| puts [pf.product_feature_type.lookup_key, pf.product_feature_type.description].inspect }
# Longhand lookup_key for a product
@tdouce
tdouce / gist:1944339
Created February 29, 2012 21:05
Not sure why 'MR Credit 5 Regional Materials' isn't show up
From console:
?> project
=> #<Project id: 1, user_id: 1, publisher_id: 2, name: "Travis_test_1", street_address: "407 Greenwood Drive", suite: "", city: "Athens", state: "GA", postal_code: "49508", country: "United States", confidential: false, owner_occupied: false, gross_square_feet: 5000, total_budget: #<BigDecimal:10b745c50,'0.5E5',9(18)>, project_type_id: nil, owner_type_id: nil, occupant_type_id: nil, project_scope_id: nil, project_phase_id: nil, session_id: nil, created_at: "2012-02-28 16:06:46", updated_at: "2012-02-29 13:41:41", saved: true, auto_project_source: true>
>> project.name
=> "Travis_test_1"
>> project.project_items
=> [#<ProjectItem id: 1, project_id: 1, product_id: 29, quantity: 1, unit_price: #<BigDecimal:10b71cff8,'0.75E2',9(18)>, postal_code_of_manufacture: "53551", params: nil, postal_code_of_fabrication: nil>, #<ProjectItem id: 2, project_id: 1, product_id: 16, quantity: 1, unit_price: #<BigDecimal:10b7164a0,'0.1E3',9(18)>, postal_code_of_manufacture: "49456", params: nil, postal_
class Individual < ActiveRecord::Base
#attr_writer :train
#attr_accessor :trained
#attr_accessible :trained
#attr_protected :trained
before_update :untrain
validates :height, :presence => true, :numericality => true
class IndividualsController < ApplicationController
def update
@individual = Individual.find(params[:id])
# When I tried to implement this as a callback I kept getting 'SystemStackError (stack level too deep)'
#@individual.untrain
if @individual.update_attributes(params[:individual])
flash[:success] = "Individual was updated"
redirect_to individuals_url
class IndividualsController < ApplicationController
def update
@individual = Individual.find(params[:id])
# When I tried to implement this as a callback I kept getting 'SystemStackError (stack level too deep)'
#@individual.untrain
if @individual.update_attributes(params[:individual])
flash[:success] = "Individual was updated"
redirect_to individuals_url
attributes = [ :weight, :height, :foot_size ]
training_data = {}
Individual::GENDERS.each do |gender|
data = []
attributes.each do |attr|
if gender == Individual::MALE
data << Individual.get_gender(gender).map(&attr)
else
@tdouce
tdouce / amware - refactor #6
Created October 18, 2011 01:42
amware - refactor #6
// When user clicks 'submit' button loop through all selects with a 'datetime' class.
// Find the select element that furtherest DOWN the DOM.
// Add a warning to any other select elememnt that has an empty value that
// is further UP the DOM
$(".commit").click( function(e){
// Html warning to append. Create a unique class name ('javascript_warning')
// to faciliate identifying and removing ONLY the warnings thata are added with this function.
// NOTE: We are piggy-backing on the existing css for the errors by using the 'inline-errors' class.
var warning_html = '<p class="inline-errors javascript_warning"> Warning, this is blank </p>';
@tdouce
tdouce / amware_custom_modal_confirmation
Created September 26, 2011 20:46
amware_custom_modal_confirmation
$(document).ready(function(){
$(".commit").click( function(e){
// To make this work we need to add the the following html to the page.
//<div id="dialog" title="Verify Form jQuery UI Style">
//<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 0 0;"></span> You entered your e-mail address as:</p>
//<p id="dialog-email"></p>
//<p>If this is correct, click Submit Form.</p>
@tdouce
tdouce / amware_javascript_warnings - final #3
Created September 22, 2011 14:02
amware_javascript_warnings - final #3
$(".commit").click( function(e){
var warning = '<p class="inline-errors"> Warning, this is blank </p>'
var all_selections = [];
var not_filled_out = [];
$( '.check_value' ).children().each( function(){
var li = $(this);
var li_value = li.val();