Skip to content

Instantly share code, notes, and snippets.

Avatar

Xander Miller xander-miller

View GitHub Profile
View kathleen_seed.rb
require 'faker'
topics = []
15.times do
topics << Topic.create(
name: Faker::Lorem.words(rand(1..10)).join(" "),
description: Faker::Lorem.paragraph(rand(1..4))
)
end
View seeds.rb
require 'faker'
topics = []
15.times do
topics << Topic.create(
name: Faker::Lorem.words(rand(1..10)).join(" "),
description: Faker::Lorem.paragraph(rand(1..4))
)
end
@xander-miller
xander-miller / bookmark.rb
Created Feb 8, 2014
Using Embedly to generate preview thumbnails for bookmark links.
View bookmark.rb
#method for your app/models/bookmark.rb
def thumbnail_url
Embedly::API.new.oembed( url: self.url).first.thumbnail_url
end
View _comment.html.erb
<div class='status'>
<div class='row'>
<div class='span7'>
<strong><%= comment.user.name %></strong>
<p><%= comment.content %></p>
<div class='meta'>
<%= link_to "#{time_ago_in_words(comment.created_at)} ago", comment %>
</div>
</div>
</div>
View show_me_the_specialities.html.erb
<ol>
<% @lawyers_specialty_questions.each do |question| %>
<li><%= question.title %></li>
<% end %>
</ol>
View exercise.rb
class String
def title_case
articles = ['a','the','of']
words_array = self.downcase.split(" ")
words_array.each do |word|
unless articles.include?(word)
word.capitalize!
end
end
words_array.first.capitalize!
View items_controller.rb
def index
@list = List.find(params[:list_id])
@items = @list.items
end
View simple_class.rb
class Book
def title_and_author(title, author)
#some stuff
end
def description
#some other stuff
end
end
View array_extension.rb
class Array
def sum
sum = 0
self.each do |item|
#some code
end
sum
end
def add_index
@xander-miller
xander-miller / application.rb
Created Mar 3, 2014
What Application.rb should look like.
View application.rb
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"