Skip to content

Instantly share code, notes, and snippets.

def to_roman(num)
numerals = {:I => 1, :V => 5, :X => 10, :L => 50, :C => 100, :D => 500, :M => 1000}
largest_less_than_array
@TKais
TKais / jquery_example.html
Last active August 29, 2015 13:57 — forked from dbc-challenges/jquery_example.html
Intro to jQuery for Phase 0
<!DOCTYPE html>
<html>
<head>
<title>DOM manipulation with jQuery</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery_example.js"></script>
</head>
<body>
@TKais
TKais / 0.2.1-boggle_class_from_methods.rb
Last active August 29, 2015 13:56 — forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
def initialize(dice_grid)
@dice_grid = dice_grid # Creates dice_grid instance variable that holds the dice_grid
end
def create_word(*coords)
coords.map { |coord| @dice_grid[coord.first][coord.last]}.join("") # Iterates over coords, locating the index of the first given coordinate and then doing the same for the last coordinate
end # returning the element found based on those index positions. It does this for as many coordinates are given, and joins the elements as a string to form a word.
@TKais
TKais / credit card
Last active August 29, 2015 13:56
Credit Card Validator
#1
class CreditCard
def initialize(credit_card_num)
@credit_card_num = credit_card_num.to_s.split('')
if @credit_card_num.length != 16
raise ArgumentError.new("Not a valid credit card number")
end
@TKais
TKais / array_mode
Last active August 29, 2015 13:55
Write a method mode which takes an Array of numbers as its input and returns an Array of the most frequent values. If there's only one most-frequent value, it returns a single-element Array.
def mode(array)
counter = Hash.new(0)
array.each {|num| counter[num] += 1}
counter.sort_by {|k,v| v }.last
end
@TKais
TKais / gist:8592234
Created January 24, 2014 04:48
count_between
def count_between(array, lower_bound, upper_bound)
if array==[]
return 0
else
array.count {|x| x>=lower_bound && x<=upper_bound}
end
end
@TKais
TKais / gist:8567843
Last active January 4, 2016 04:19
Exercise: Print out a pretty right triangle
# print_triangle(rows) prints out a right triangle of +rows+ rows consisting
# of * characters
#
# +rows+ is an integer
#
# For example, print_triangle(4) should print out the following:
# *
# **
# ***
# ****
@TKais
TKais / gist:7934070
Created December 12, 2013 19:38
HTML: Starter Template
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title></title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>