Skip to content

Instantly share code, notes, and snippets.

View ntijoh-daniel-berg's full-sized avatar

Daniel Berg ntijoh-daniel-berg

  • IT-Gymnasiet Göteborg
View GitHub Profile
require 'chingu'
class Game < Chingu::Window
def initialize
super
self.input = {esc: :exit}
Player1.create
Player2.create
end
require 'chingu'
class Game < Chingu::Window
def initialize
super
self.input = {esc: :exit}
8.times {|i| Cursor.create(angle: i * 45 ) }
end

Instruktioner för att förbereda din mac för att utveckla i ruby

1 Installera Homebrew

Homebrew är en pakethanterare, det vill säga ett program som används för att hämta, kompilera, och installera program.

  1. Starta terminalen
  2. Hämta och installera homebrew: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  3. Skriv in ditt lösenord för datorn (inget kommer synas på skärmen) och tryck på enter
$ ->
console.log('ready')
getSuggestions()
$('body').on 'submit', '.remover', ->
removeSuggestion($(this), event)
event.preventDefault()
removeSuggestion = (form, event) ->
$.ajax
def print_names(names:)
# i = 1
# while i < names.length
# puts names[i].upcase
# i += 1
# end
# for name in names
# puts name.upcase
# end
class NegativeAmountPaidError < ArgumentError; end
class NotEnoughPaidError < ArgumentError; end
def change_o_matic(price:, amount_paid:)
if amount_paid <= 0
raise NegativeAmountPaidError, "amount_paid (#{amount_paid}) must not be negative or zero"
elsif price > amount_paid
raise NotEnoughPaidError, "amount paid (#{amount_paid}) must not be less than price (#{price})"
end
def change_o_matic(price, amount_paid):
amount_due = amount_paid - price
if amount_due < 0:
raise ValueError("amount paid ({0}) must not be less than price ({1}) ".format(amount_paid, price))
change = {1000: 0, 500: 0, 200: 0, 100: 0,
50: 0, 20: 0, 10: 0, 5: 0, 2: 0, 1: 0 }
denominations = sorted(change.keys(), reverse=True)
for den in denominations:
while amount_due >= den:
import glob
def list_files_in_folder():
files_and_folders = glob.glob('*.*')
for thing in files_and_folders:
print(thing)
def ask_for_file_name():
def countdown(start):
""" creates a list of numbers from start to zero
:param start: (int) the starting value
:return: the list of numbers
:rtype: list
:raises ValueError: if start is less than 1
Example:
countdown(start=3) >>> [3, 2, 1 0]
def list_files_in_dir
files = Dir.glob('*.*')
files.each_with_index do |file, i|
puts "#{i + 1}: #{file}"
end
end
def ask_for_filename
print 'Enter name of file to open '
filename = gets.chomp