Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Waldo Lavaut waldothedeveloper

🏠
Working from home
View GitHub Profile
View repl_game.rb
# Title and Rules of the Game
puts "Welcome to the Purrfect Game of Insane Cats =ˆ.ˆ= "
puts "Rule 1: Choose your cat"
puts "Rule 2: Type A or B only to select an option"
puts "Ready? Here we go"
# Starting the actual game
puts "Choose your cat (Type just the name):"
puts "Vivaldi =ˆ.ˆ="
puts "Adele =ˆ.ˆ="
@waldothedeveloper
waldothedeveloper / url_parser.rb
Last active Jul 18, 2017
URL_PARSER homework
View url_parser.rb
class UrlParser
def initialize(new_url)
@new_url = new_url
end
def scheme
@new_url.split("://")[0]
end
View bank_account.rb
class BankAccount
attr_reader :balance
@@minimum_balance = 200
def initialize(opening_balance, account_holder)
raise ArgumentError if opening_balance < @@minimum_balance
@balance = opening_balance
end
def deposit amount
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Gmail</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<main>
View filters.markdown

Controller Filters

The Rails REST implementation dictates the default seven actions for your controllers, but frequently we want to share functionality across multiple actions or even across controllers. Controller filters are the easiest way to do that.

Before, After, and Around

There are three types of filters implemented in Rails:

  • a before_filter runs before the controller action
  • an after_filter runs after the controller action
View dry_controller.rb
class UsersController < ApplicationController
after_action :notify_slack, only: [:create, :update, :destroy]
before_action :set_user, only: [:show, :edit, :update, :destroy]
def index
@users = User.all
end
def show
end
View gist:d08320a8033327c33dcf9764ada688b3

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

View capybara cheat sheet
=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')
@waldothedeveloper
waldothedeveloper / app.js
Created May 17, 2018
FreeCodeCamp Random Quotes App
View app.js
$(document).ready(() => {
console.log('ready!');
$("i#tweet-icon").on("click", () => {
let quote = $.trim($("#quote").text());
window.open(`https://twitter.com/intent/tweet?text=${quote}`);
});
let endpoint = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?';
@waldothedeveloper
waldothedeveloper / index.html
Created May 18, 2018
The HTML file for this challenge
View index.html
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">