Skip to content

Instantly share code, notes, and snippets.

View radar's full-sized avatar

Ryan Bigg radar

View GitHub Profile
filename = "a.b c.a"
parts = filename.split(".")
last_index_of_space = parts.index(parts.grep(/ /).last)
suffix = parts[last_index_of_space + 1..-1]
prefix = parts[0..last_index_of_space].join(".")
p [prefix, suffix]
module CommentsHelper
def putstree(text,hash,depth,trusted)
hash.each_pair do |k,v|
text << (render :partial => "shared/comment", :locals => {:trusted => trusted, :comment => k, :depth => depth})
if v != {}
putstree(text,v,depth+1,trusted)
end
end
if depth == 0
text
@radar
radar / _contractors.html.erb
Created August 31, 2012 10:31 — forked from glennmartinez/_contractors.html.erb
not getting quote.id from return ajax search
<table>
<% @contractors.each do |contractor| %>
<tr>
<td><%= contractor.firstname %></td>
<td>
<%= button_to("Add", add_contractor_quote_path(@quote, :contractor_id => contractor.id)) %>
</td>
</tr>
<% end %>
</table>
<% @orders.each do |order| %>
<% if order.authorized %>
<tr class="order_authorized">
<% else %>
<tr>
<% end %>
<td><%= link_to order.user.email, user_path(order.user) %></td>
<td><%= link_to order.id, order_path(order) %></td>
<td><%= order.created_at.strftime("%d %B %Y") %></td>
<td><%= number_to_currency(order.line_items.sum(:price), :unit => "€") %></td>
class OtoplastikCustomer < Customer
def otoplastik?
true
end
def find_prices(article_id, merchant_id)
OtoplastikArticlePrice.where("otoplastik_article_id = ? AND merchant_code = ?", article.id, self.id).order("minimum DESC")
end
def prices(article)
<select id="membership_id" name="membership[id]"><option value="IG">Inspector General (CO) (LTC)</option>
<option value="IG">Inspector General (CO) (LTC)</option>
<option value="NU2013">Class of 2013 (STU)</option></select
@radar
radar / gist:3038312
Created July 3, 2012 07:42 — forked from johncausey/gist:3038304
Finding a record meeting two requirements
Conversation.where("(user_id = :current_user OR user_id = :other_user) AND (recipient_id = :current_user OR recipient_id = :other_user)", :current_user => current_user.id, :other_user => user.id)
require 'spec_helper'
describe "Session" do
describe "GET /auth/facebook and /session/create (same as /auth/facebook/callback)" do
it "triggers callback, creates Bob and redirects to root" do
User.count.should == 0
Login.count.should == 0
get '/auth/facebook'
User.count.should == 1
Login.count.should == 1
#app/views/users/edit.html.erb
...
<%= content_tag(:label, :class => 'add-on') { 'ft.' } %>
@radar
radar / 1_explanation
Created May 31, 2012 22:47 — forked from kwiest/gist:2845726
Redis Cannot Connect Error
# When I run the test when Redis is running, all tests pass
# When I run the test with Redis purposefully off, I get the error at the end of the gist
#
# I've tried manually raising Redis::CannotConnectError instead of calling Redis.new
# and a new instance of SimpleStore is returned, and again all tests pass
# Gemfile
gem 'redis', '~> 3.0.0'