Skip to content

Instantly share code, notes, and snippets.

@markmcspadden
Created December 7, 2010 16:13
Show Gist options
  • Save markmcspadden/731972 to your computer and use it in GitHub Desktop.
Save markmcspadden/731972 to your computer and use it in GitHub Desktop.
My most shameful and most favoritest Ruby chunks of 2010.
# Part of the Dallas Ruby "A Year in Code" December 2010 meeting.
# http://groups.google.com/group/dallasrb/browse_thread/thread/1c114671b17dd81f
# Shame
# Yes it was committed.
# Yes I did come up with something better before it went to production. :)
<% 60.times do %>&nbsp;<% end %>
----
# Favorite #1
# It's not super special but it represented a few things for me:
# 1. The benefits of following impressive Ruby people on twitter. @jeg2 mentioned how awesome it is to use String#[/regex/]. Did not know that.
# 2. Yes it's a fairly simple regex, but the big deal to me was that I used it without having to stop and go into "Regex mode"...it just kind of happened and when I realized it was case sensitive and I didn't want it to be, I added the 'i' at the end...like I knew what I was doing
medical_regex = /(doctor|hospital|sick|virus)/i
@medicals = @feed.data.select{ |f| f.message.to_s[medical_regex] }
# Favorite #2
# Really this one is just a "are you sure you can do that" kind of favorite.
# I know...I know...just because you can doesn't mean you should...there were reasons
# One day I can definitely see me moving this to the most shameful category. ;)
<div class="content">
<div id="qaQuestion<%=@question_summary.id%>" class="question <%=@question_summary.id%> single_item list_item">
<%# MM2: I want to force the large avatar, but really don't want to copy the helper or partial from cubeless into here %>
<% self.instance_eval do
alias :link_to_avatar_for_from_cubeless :link_to_avatar_for
def link_to_avatar_for(profile, options={})
link_to_avatar_for_from_cubeless(profile, options.merge!({:thumb => :thumb_large}))
end
end
%>
<%= render :partial =>'questions/question', :locals => {:question => @question_summary, :show => {:linked_question => false, :close => true}}%>
<%# MM2: Put everything back to normal after my big avatar is rendered %>
<% self.instance_eval { alias :link_to_avatar_for :link_to_avatar_for_from_cubeless } %>
<%= render(:partial => 'answers/best_answer', :locals => {:answer => @best_answer}) %>
<div style="clear: both;"></div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment