Skip to content

Instantly share code, notes, and snippets.

View michaeldhopkins's full-sized avatar

Michael Hopkins michaeldhopkins

View GitHub Profile
<ul class="ortho-in-motion cf"><?php
$i = 0;
$number_of_posts_output = 0;
$number_of_posts_output_by_doctor = 0;
$length_of_xml = count($xml->channel); //I forget how to do this
foreach ($xml->channel->item as $entry){
$i++;
if (author_of_this_post_is_current_doctor()) {
echo "<li>post</li>";
@michaeldhopkins
michaeldhopkins / gist:1762184
Created February 7, 2012 21:36
Why did this fail?
michael-hopkinss-macbook-pro:grbc Michael$ git push heroku master
Counting objects: 90, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (60/60), done.
Writing objects: 100% (60/60), 9.10 KiB, done.
Total 60 (delta 38), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.rc.7
@michaeldhopkins
michaeldhopkins / gist:1761169
Created February 7, 2012 18:42
why aren't these returning unique?
ruby-1.9.2-p290 :056 > Sermon.where("date > ?", Date.today - 365).select(:speaker_id).uniq
Sermon Load (0.5ms) SELECT speaker_id FROM "sermons" WHERE (date > '2011-02-07')
=> [#<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>, #<Sermon speaker_id: 1>]
Update: answer:
ruby-1.9.2-p290 :070 > Sermon.select(:speaker_id).where("date > ?", Date.today - 365).group(:speaker_id)
Sermon Load (0.5ms) SELECT speaker_id FROM "sermons" WHERE (date > '2011-02-07') GROUP BY speaker_id
=> [#<Sermon speaker_id: 1>]
irb(main):032:0> s.date = "11/9/2007"
=> "11/9/2007"
irb(main):033:0> s.date
=> Tue, 11 Sep 2007 00:00:00 UTC +00:00
irb(main):034:0> s.date = "2007/11/9"
=> "2007/11/9"
irb(main):035:0> s.date
=> Fri, 09 Nov 2007 00:00:00 UTC +00:00
irb(main):036:0>
$(document).ready ->
$('#menu li a').hover ->
$(this).animate({backgroundColor:'#7c9344'},'fast')
$(this).animate({backgroundColor:'#f6fcfc'},'fast')
application.html.erb:
<%= generate_menu_link do %> <%= link_to "Home", :controller => "pages", :action => "show" %> <% end %>
application_helper.erb:
def generate_menu_link(&block)
link = with_output_buffer(&block)
li = ""
if is_link_to_current_page?(link)
show.erb:
<div id="slideshow">
<%=
image_tag("GRBC_bible.gif")
image_tag("Hymn.jpg")
image_tag("world_map.jpeg")
%>
</div>
@michaeldhopkins
michaeldhopkins / rails routing
Created November 1, 2011 03:32
Rails routing not working
Problem: trying to create a new gyro which belongs to restaurant results in
No route matches {:controller=>"gyros", :format=>nil}
Details follow. Most of the code is scaffolded, with some minor tweaks related to nesting gyros inside restaurants.
Restaurants_controller.rb:
def show
@restaurant = Restaurant.find(params[:id])
@gyros = @restaurant.gyros