Skip to content

Instantly share code, notes, and snippets.

View waldothedeveloper's full-sized avatar
🎖️
Never give up!

Waldo Lavaut waldothedeveloper

🎖️
Never give up!
View GitHub Profile
@waldothedeveloper
waldothedeveloper / repl_game.rb
Created July 11, 2017 16:38
Purrfect Insane Cats
# 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 July 18, 2017 01:13
URL_PARSER homework
class UrlParser
def initialize(new_url)
@new_url = new_url
end
def scheme
@new_url.split("://")[0]
end
@waldothedeveloper
waldothedeveloper / bank_account.rb
Last active July 17, 2017 19:12
Bank Account HM
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
<!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>
@waldothedeveloper
waldothedeveloper / filters.markdown
Created August 10, 2017 20:38 — forked from jcasimir/filters.markdown
Controller Filters

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
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

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

=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 22:29
FreeCodeCamp Random Quotes App
$(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 11:36
The HTML file for this challenge
<!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">