Skip to content

Instantly share code, notes, and snippets.

View lkrych's full-sized avatar

Leland Krych lkrych

  • Cisco
  • San Francisco, CA
View GitHub Profile
@lkrych
lkrych / movies_controller_update_spec.rb
Created October 18, 2016 15:02
Empty RSpec file for update method in movies_controller
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
describe "PUT #update" do
it "located the requested movie" do
end
it "changed the requested movies attributes" do
end
it "redirects to the updated movie" do
@lkrych
lkrych / complete_movies_controller_update_spec.rb
Created October 18, 2016 15:05
Completed RSpec for update method in movies_controller
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
before (:each) do
@mock_movie_attributes = {:title => 'Space Balls', :release_date => '24/6/1987', :rating => 'PG'}
@mock_movie = FactoryGirl.create(:movie)
end
describe "PUT #update" do
it "located the requested movie" do
@lkrych
lkrych / movies_controller_delete_spec.rb
Created October 18, 2016 15:12
Empty RSpec file to test delete method in movies_controller
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
describe "DELETE #destroy" do
it "deletes the movie" do
end
it "redirects to the main page " do
end
end
@lkrych
lkrych / complete_movies_controller_delete_spec.rb
Created October 18, 2016 15:15
Complete RSpec file to test the delete method in the movies_controller
require 'rails_helper'
RSpec.describe MoviesController, type: :controller do
before (:each) do
@mock_movie_attributes = {:title => 'Space Balls', :release_date => '24/6/1987', :rating => 'PG'}
@mock_movie = FactoryGirl.create(:movie)
end
describe "DELETE #destroy" do
@lkrych
lkrych / Hamming_naive.rb
Created November 3, 2016 12:45
Naive implementation of Hamming distance for exercism.io
class Hamming
def self.compute(s1,s2)
if s1.length != s2.length
raise ArgumentError
else
index = 0
count = 0
while index < (s1.length)
if s1[index] != s2[index]
count += 1
@lkrych
lkrych / Hamming_improved_2.rb
Last active November 3, 2016 15:22
An improved implementation of the Hamming distance
class Hamming
def self.compute(s1,s2)
distance = 0
raise ArgumentError if s1.length != s2.length
s1.chars.zip(s2.chars) {|s1char, s2char| distance += 1 unless s1char == s2char}
distance
end
end
end
@lkrych
lkrych / Hamming_improved.rb
Created November 3, 2016 15:17
Almost the same as Hamming_improved_2.rb
class Hamming
def self.compute(s1,s2)
distance = 0
if s1.length != s2.length
raise ArgumentError
else
s1.chars.zip(s2.chars) {|s1char, s2char| distance += 1 unless s1char == s2char}
return distance
end
end
@lkrych
lkrych / credit.c
Created November 8, 2016 01:07
c implementation of credit card problem from HW1 in CS50
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int countDigits(long long num) { // helper method that counts the number of digits in a number
int count = 0;
while (num != 0) {
num /= 10;
++count;
@lkrych
lkrych / credit_naive.rb
Created November 8, 2016 02:02
Naive Ruby implementation of checksum algorithm
def credit_card_check() #main ruby method
credit_card_no = 0
loop do #get credit card number
puts "Number: "
credit_card_no = gets.chomp
size = credit_card_no.to_s.size
break if size >= 13 && size <= 16
end
cardValid = checkCredit(credit_card_no)
if cardValid == false
@lkrych
lkrych / credit_refactor.rb
Last active November 8, 2016 16:29
Refactored ruby implementation of credit problem.
def credit_card_check() #main ruby method
credit_card_no = 0
until [13,14,15,16].include? credit_card_no.to_s.size #get credit card number
puts "Number: "
credit_card_no = gets.chomp
end
cardValid = checkCredit(credit_card_no)
if cardValid == false
puts "INVALID"