Skip to content

Instantly share code, notes, and snippets.

@kangkyu
kangkyu / clock.rb
Created October 7, 2015 02:44
Go Mobs!
class Clock
def self.at(hours=0, minutes=0)
new(hours, minutes)
end
def initialize(hours=0, minutes=0)
array = minutes.divmod 60
@minutes = array[1]
@hours = array[0] + hours
@kangkyu
kangkyu / all_the_same_digit_numbers.rb
Created October 31, 2015 21:30
Today's Kata 10-29-2015
# Today's kata:
# Given a 3 or 4 digit number with distinct digits, return a sorted array of all the unique numbers that can be formed with those digits.
# ie, given 123, return [123, 132, 213, 231, 312, 321]
def same_digit_numbers(initial_num)
initial_num.to_s.split('').permutation.map {|e| e.join.to_i }.uniq.sort
end
def same_digit_numbers(initial_num)
num_string = initial_num.to_s
@kangkyu
kangkyu / word_count.rb
Created November 1, 2015 04:59
Today's Kata 10-30-2015
# today's code kata: Write a function called word_count, that takes a sentence as a string as input, and returns the frequency of each word in that sentence, as a hash whose key is the word, and whose count is the number of times that word appears in that sentence.
# 1) ignore case, 2) ignore any non word characters
# Here is the paragraph:
# The quick brown fox jumped over the moon. This mammal did not jump over the sun; it jumped over the moon. And it was quick about it.
# let's use the whole paragraph
def word_count(paragraph)
paragraph.split(/\W+/).map(&:downcase).each_with_object(Hash.new(0)) {|w, hsh| hsh[w] += 1 }
end
# She has asked you to create a method print_puzzle that prints the row of dashes for a required, single argument, word. The number of dashes or spaces should equal the amount of characters in the word. print_puzzle can also optionally take a list of characters as a second argument that represents the list of guessed letters.
# Given print_puzzle is called with the word "perimeter", your method should output: _ _ _ _ _ _ _ _ _
# Given print_puzzle is called with the word "triangle" and the list of characters guessed: t,s,g, your method should output: t _ _ _ _ g _ _
def print_puzzle(word, guessed_letters = [])
word.chars.map {|char| guessed_letters.include?(char) ? " #{char}" : " _"}.join
end
gem 'minitest'
require 'minitest/autorun'
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
def reverse(string)
result = ""
string.length.times do |i|
result = string[i] + result
end
result
end
@kangkyu
kangkyu / plus_minus.rb
Last active November 4, 2015 06:57
Today's Kata 11-03-2015
# For today, here's the problem for today
# Do whatever you need to do to Ruby, such that I can say: 9 - 8, and the answer will be 17
# And if I say 9 + 8, the answer will be 1
# so - i load whatever code you want to give me via a console, and I should be able to do the above
# turn plus into minus, minus into plus
# a short sentence explaining what you did and why it works would be nice
class Fixnum
alias_method :temp, :+
alias_method :+, :-
@kangkyu
kangkyu / random_number.rb
Created November 11, 2015 00:02
Today's Kata 11-10-2015
# add a logger to this class, such that there is only one logger, that writes to a file called ./logfile.txt
class Charlie
class Logger
def self.log(number)
File.open("./logfile.txt", "a") do |f|
f.puts "#{number}"
end
@kangkyu
kangkyu / mixin_module.rb
Last active November 15, 2015 23:08
Today's Kata 11-13-2015
=begin
# Question 1. A mixin is a module whose methods you want to use in more than one class. One popular interview question is: How do you use module methods as class methods, and how to you use them as instance methods? In other words, given this module ...
module Mixin
def method1
'method1'
end
end
@kangkyu
kangkyu / exercism_osx.markdown
Last active January 16, 2016 18:15
Setup exercism.io in macOS X
  1. go to exercism.io and login with github account
  2. get your api key (navbar > username > api key)
  3. install exercism brew install exercism in OSX
  4. and set api key to exercism cli http://exercism.io/cli
@kangkyu
kangkyu / el_capitan_osx.markdown
Last active January 16, 2016 18:22
El Capitan change on macOS X
  1. install command-line tool matching OS X version
  2. homebrew / npm
sudo chown -R $(whoami):admin /usr/local
  1. eventmachine
PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig" gem install eventmachine