Skip to content

Instantly share code, notes, and snippets.

View rodloboz's full-sized avatar

Rui Freitas rodloboz

View GitHub Profile
# Red Green Blue - > RGB
# English Premier League - > EPL
def acronym(sentence)
# TODO: Define a method that returns the acronyms
# of a sentence, using a stronger iterator than #each
# split setence into words (split)
# go through each element
# grab the first letter and capitalize it
# Welcome user
# Display list of horses / roster [array]
# User picks a horse
# Randomly select winning horse (sample) / (shuffle)
# Determine if user won
# Display results
# Ask user if they want to play again
# 0 1 2 3
HORSES = ["Bronco", "Tweaker", "Michael Bolton", "Jack Sparrow", "John Wayne"]
# Welcome the user
# Display the stock/list of products
# Get user choice
# ask quantity
# save quantity
# Check if it's available
# Add to cart
# Ask if they want continue shoppinh
# Add total and display bill
# Write a #french_ssn_info method extracting infos from French SSN (Social Security Number) using regexp.
# Valid French SSN numbers have the following pattern:
# "1 84 12 76 451 089 46"
# Gender (1 == man, 2 == woman)
# Year of birth (84)
# Month of birth (12)
# Department of birth (76, basically included between 01 and 99)
# Welcome user
# LISTS: collections of records (Array)
# RECORDS: objects w/ attributes (name, etc...)
# (loop)
# Get user which action [list|add|delete|quit]
# Check if action exists
# LIST
require 'sqlite3'
require 'byebug'
# ruby multi-line syntax:
# <<-SQL (SQL is a tag name of your choosing)
# string line 1
# string line 2
# ...
# SQL (closes the tag)
@rodloboz
rodloboz / restaurants_controller.rb
Last active April 11, 2018 07:19
Rails Slug Filtering
# Set up a /slug/ route to your #index in routes.rb
# get '/search/:slug', to: 'restaurants#index'
class RestaurantsController < ApplicationController
def index
if params[:slug]
lookup = SlugLookupService.new(params[:slug])
lookup.perform
category = lookup.category
redirect_to restaurants_path unless category
lisbon = {
# key => value
"country" => "Portugal", # string
"population" => 2821876 # integer
}
# puts Lisbon.class
# uninitialized constant Lisbon (NameError)
# the program does not know a variable/constant named Paris
# (because we have not defined one)
# #frequencies method
# should return and empty hash when passed an empty string
# should count words
# should count multiple words
# should be case insensitive
# should ignore short words and punctuation (. ! ? ,)
# #read_file method
# should read the dummy file
def calculate(first_number, second_number, operator)
case operator
when "+"
first_number + second_number
when "-"
first_number - second_number
when "*"
first_number * second_number
when "/"
first_number / second_number