Skip to content

Instantly share code, notes, and snippets.

View xander-miller's full-sized avatar

Xander Miller xander-miller

View GitHub Profile
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
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 February 8, 2014 15:11
Using Embedly to generate preview thumbnails for bookmark links.
#method for your app/models/bookmark.rb
def thumbnail_url
Embedly::API.new.oembed( url: self.url).first.thumbnail_url
end
<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>
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!
<ol>
<% @lawyers_specialty_questions.each do |question| %>
<li><%= question.title %></li>
<% end %>
</ol>
def index
@list = List.find(params[:list_id])
@items = @list.items
end
@xander-miller
xander-miller / simple_class.rb
Created March 1, 2014 14:52
Sheldon Exercise
class Book
def title_and_author(title, author)
#some stuff
end
def description
#some other stuff
end
end
@xander-miller
xander-miller / array_extension.rb
Created March 2, 2014 16:13
Sheldon's exercise
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 March 3, 2014 22:21
What Application.rb should look like.
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"