Skip to content

Instantly share code, notes, and snippets.

View davidphasson's full-sized avatar

David Hasson davidphasson

  • Los Angeles, CA
View GitHub Profile
<%= javascript_include_tag "dynamic.1226508100" %>
// Operates on tabs with class "form_tab" - hides all but "tabname"
function switch_tab(tabname)
{
tabs = $$('.form_tab');
for ( var i in tabs )
{
tab = tabs[i];
(tabname == tab.id) ? tab.show() : tab.hide();
}
scroll(0,0);
class Request < ActiveRecord::Base
# Page 1
validates_presence_of :school, :assembly_type, :starting_grade, :ending_grade, :num_students, :author_hosted, :mike_hosted
validates_numericality_of :num_students, :message => "is not a valid number"
# Current hacked validation - 1..4 are radio options, otherwise look for a date
validates_inclusion_of :mike_hosted, :in => (1950..(Date.today.year)).to_a + (1..4).to_a, :message => "is an invalid date"
# :unless => Proc.new { |r| r.varable <test> })
def new
@request = Request.new
# This needs to go somewhere else
@request.lunch_with_mike = true
end
<!-- Scroll works on these links -->
<div id="navbar" style="padding: 5px;">
<%= f.tab_button "general", link_to_function("General", "switch_tab('page_general');"), general_fields, { :current => true } %>
<%= f.tab_button "contact", link_to_function("Contact", "switch_tab('page_contact');"), contact_fields %>
<%= f.tab_button "dates", link_to_function("Dates", "switch_tab('page_dates');"), date_fields %>
<%= f.tab_button "times", link_to_function("Times", "switch_tab('page_times');"), time_fields %>
<%= f.tab_button "questions", link_to_function("Questions", "switch_tab('page_questions');"), question_fields %>
<%= f.tab_button "multisite", link_to_function("Multi-School Visits", "switch_tab('page_multisite');"), multisite_fields %>
<%= f.tab_button "comments", link_to_function("Comments", "switch_tab('page_comments');"), comment_fields %>
# Time specifications:
validates_each :assembly_time2 do |record, attr, value|
next if value.nil?
# Leave this up to other validation
next if record.assembly_time1.nil?
if value < ( record.assembly_time1 + 1.hour + 15.minutes )
record.errors.add attr, "must allow for at least one hour assembly and 15 minute break"
end
end
validates_each :assembly_time3 do |record, attr, value|
@davidphasson
davidphasson / show.html.erb
Created April 8, 2009 03:42
ERB and the case statement
# Doesn't work
<p>
<% case @request.author_hosted %>
<% when "yes" %>
The school <b>has</b> hosted an author before.
<% when "no" %>
The school <b>has not</b> hosted an author before.
<% end %>
</p>
@davidphasson
davidphasson / application_controller.rb
Created April 8, 2009 22:33 — forked from bensie/application_controller.rb
HTTP Basic Authentication
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "joe" && password == "secret"
end
end
@davidphasson
davidphasson / gist:92124
Created April 8, 2009 23:22
Mac pbcopy
[~/.ssh]$ cat id_dsa.pub | pbcopy
@davidphasson
davidphasson / gist:93177
Created April 10, 2009 17:00 — forked from anonymous/gist:93135
PPTP from Dr. Trout
/etc/options
#debug
proxyarp
#+MSChap-V2 mppe-128 mppe-stateless
##require-mschap-v2
##require-mppe-128
ms-dns 192.168.100.1
/etc/options.pptpd
# Authentication