Skip to content

Instantly share code, notes, and snippets.

@irmiller22
irmiller22 / factorial.rb
Created October 16, 2013 03:45
factorial
def factorial(num)
if num <= 1
1
else
num * factorial(num-1)
end
end
@irmiller22
irmiller22 / config.ru
Created October 21, 2013 14:22
hello_rack
# require 'Rack'
# class YourAppClass
# def call(env)
# [200, {'Content-Type' => 'text/html'}, ['Hello Rack!']]
# end
# end
# run YourAppClass.new
@irmiller22
irmiller22 / gist:7418546
Created November 11, 2013 19:06
Database Checklist
does it change the database?
where am I going to store that data?
what data needs to be stored?
name
the songs on the mixtape
- write my migration
how does that effect my models?
@irmiller22
irmiller22 / greed_score_method
Created December 6, 2013 19:16
Greed Score Logic
# GREED GAME
def score(dice)
return 0 if dice == nil
score = 0
counts = [0,0,0,0,0,0]
dice.each { |roll| counts[roll-1] += 1 if (1..6) === roll }
source 'https://rubygems.org'
# Frameworks
gem 'rails', '4.0.2'
# Server
gem 'unicorn'
# Database
gem 'pg'
@irmiller22
irmiller22 / flatiron_scrape.rb
Created February 16, 2014 22:37
Flatiron Scraper
require 'nokogiri'
require 'open-uri'
require 'pry'
class Scraper
def initialize
@student_data = []
@index_url = "http://students.flatironschool.com/"
@index = Nokogiri::HTML(open(@index_url))
@irmiller22
irmiller22 / rspec_rails_env.md
Last active August 29, 2015 13:56
RSpec Testing for Rails

Setting up RSpec-Rails

Generate RSpec testing

rails g rspec:install

config/applications.rb

config.generators do |g| g.test_framework :rspec, fixtures: true,

=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@irmiller22
irmiller22 / kickstarter.rb
Created February 23, 2014 21:41
Kickstarter_scrape
# Kickstarter Project Scrape
require 'nokogiri'
# HTML, XML parser that allows us to view HTML code as series of nodes; able to highlight elements via CSS selectors
require 'open-uri'
# Module that allows you to make http request, and returns us the HTML content of a URL via the `open` command
require 'pry'
# projects
# kickstarter.css("li.project.grid_4")
@irmiller22
irmiller22 / forms.md
Last active August 29, 2015 14:03
Rails Forms

Form_for

  • Most magical form helper in rails
  • form_for is a ruby method into which a ruby object is passed
  • form_for yields a form builder object (typically f)
  • methods to create form controls are called on f, the form builder element
  • when the object is passed as a form_for parameter, it creates corresponding inputs with each of the attributes
    • if i had form_for(@cat), then the form field params would look like cat[name], cat[color], etc
  • in keeping with Rails convention regarding RESTful routes, there should be a resource declared for each model object (eg, resources :cats)