Skip to content

Instantly share code, notes, and snippets.

View therod's full-sized avatar

Rodrigo therod

View GitHub Profile

Ruby Cheatsheet

Basic Math Operations

5.4 - 2.2 # Subtraction
4 * 72 # Multiplication
7 / 3.5 # Division
3 ** 7  # Exponentiation
class Person
attr_accessor :first_name, :last_name, :birth_year, :car_registration
def initialize(first_name, last_name, birth_year, car_registration)
@first_name = PersonDataChecker.check_name(first_name)
@last_name = PersonDataChecker.check_name(last_name)
@birth_year = PersonDataChecker.check_birth_year(birth_year)
@car_registration = PersonDataChecker.check_car_registration(car_registration)
end
end
! Disable everything but the search & video player on YouTube.
www.youtube.com###primary > .ytd-two-column-browse-results-renderer.style-scope
www.youtube.com###secondary
www.youtube.com###guide-inner-content
www.youtube.com##ytd-mini-guide-renderer
www.youtube.com##ytd-watch-next-secondary-results-renderer
mentors = ["Hans", "Ruedi"].shuffle
attendees = ["Klara", "Kevin", "Mike", "Sandro", "Sandy", "Silvan", "Lala"].shuffle
number_of_groups = (attendees.count / mentors.count)
groups = attendees.each_slice(number_of_groups).to_a
mentors.each_with_index do |mentor, index|
puts "Group #{index + 1}: #{mentor}"
puts "===================="
puts groups.shift
require 'pry'
keys = `aws s3api list-objects --bucket master21 --query 'Contents[].{Key: Key}' --output text | grep -v 'folder'`
keys = keys.split("\n")
keys.each do |key|
system("aws s3api put-object-acl --acl bucket-owner-full-control --bucket master21 --key '#{key}'")
end
require 'open-uri'
require 'prawn'
class OrangeTree
def initialize
@height = 0
@orange_count = 0
@fruit = 0
@age = 0
#!/bin/bash
## Remove all local timemachine backups
for i in $(tmutil listlocalsnapshotdates / | awk '{print $1}' | sed -n '1!p' | xargs echo); do tmutil deletelocalsnapshots $i; done
puts "Ha! Did you really think I would give away the solution that easily?"
puts "Try again!"
class OrangeTree
def initialize
@height = 0
@age = 0
@oranges = 0
@alive = true
end
def one_year_passes
@alive = false if @height > 10 && rand(2) == 1
require 'date'
require 'active_support/all'
class Person
attr_accessor :name, :birthdate, :favorite_color
def initialize(name, birthdate, favorite_color)
@name = name
@birthdate = birthdate
@favorite_color = favorite_color