Skip to content

Instantly share code, notes, and snippets.

View dev-nyc's full-sized avatar
🤹‍♂️
pushing

khaled dev-nyc

🤹‍♂️
pushing
View GitHub Profile
# car loan calculator
# methods
def prompt(message)
puts("=>#{message}")
end
def number_valid(num)
num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
end
# car loan calculator
def prompt(message)
puts("=>#{message}")
end
def number_valid(num)
num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/
end
def integer?(input)
def prompt(message)
puts("=>#{message}")
end
GAME = %w(rock paper scissors lizard spoke)
def shorten_input(input)
case input
when "p" , "P" , "paper"
input = "paper"
def prompt(message)
puts("=>#{message}")
end
GAME = %w(rock paper scissors lizard spoke)
def shorten(input)
case input
when "p" , "P" , "paper"
input = "paper"
@dev-nyc
dev-nyc / tic
Last active May 27, 2016 00:08
``` ruby
BOARD = ["a1" , "a2" , "a3" , "b1" , "b2" , "b3" , "c1" , "c2" , "c3"]
MARKER =[]
user_array = []
computer_array = []
def prompt(message)
puts message
end
def win?(player_array)
arr1 = [1,2,3,4]
arr2 = ['a', 'b', 'c', 'd']
def interleave(arr1, arr2)
newarr = []
arr1.each do |num|
newarr << num << arr2[arr1.index(num)]
end
p newarr
end
I reviewed some common Ruby methods and grouped them by behavior.
Hopefully this helps someone else too.
[Please copy paste and fix typos, add/delete, improve from this Gist.](https://gist.github.com/dirkdirk/9209d7ea67ac57543975162713910224)
-
# Array
@dev-nyc
dev-nyc / sort.rb
Created October 25, 2016 19:07 — forked from aspyct/sort.rb
Sample implementation of quicksort, mergesort and binary search in ruby
# Sample implementation of quicksort and mergesort in ruby
# Both algorithm sort in O(n * lg(n)) time
# Quicksort works inplace, where mergesort works in a new array
def quicksort(array, from=0, to=nil)
if to == nil
# Sort the whole array, by default
to = array.count - 1
end
@dev-nyc
dev-nyc / rps_bonus.rb
Last active August 14, 2017 03:09
rps bonus features
class Move
attr_accessor :value
VALID_CHOICES = ["rock", "paper", "scissors", "lizard", "spoke"]
def initialize(value)
@value = value
end
def to_s
@value
end
@dev-nyc
dev-nyc / skeleton.html
Created September 9, 2018 20:41
skeleton
<!DOCTYPE html>
<html lang="en">
<head>
<title>your page title goes here</title>
<meta charset="utf-8" />
</head>
<body>
</body>
</html>