Skip to content

Instantly share code, notes, and snippets.

@graemeboy
graemeboy / fayes4.rb
Last active April 9, 2016 19:20
Example after refactor
class NewRental
def identifier
'a latest movie'
end
def price(days_rented)
NewRentalPrice.new(days_rented).amount
end
end
@graemeboy
graemeboy / fayes3.rb
Created April 9, 2016 18:50
Examples of smaller classes
class ClassicRentalPrice
attr_reader :days_rented
def initialize(days_rented)
@days_rented = days_rented
end
def amount
2 * days_rented
end
@graemeboy
graemeboy / fayes2.rb
Last active April 9, 2016 19:20
Example after minor refactor
class Rental
attr_reader :price, :statement, :days_rented, :movie_type
def initialize(days_rented, movie_type)
@days_rented = days_rented
@movie_type = movie_type
@price = calculate_price
@statement = calculate_statement
end
@graemeboy
graemeboy / fayes1.rb
Last active April 9, 2016 19:19
Example of functionality before refactor
class Rental
attr_reader :days_rented, :movie_type
def initialize(days_rented, movie_type)
@days_rented = days_rented
@movie_type = movie_type
end
def price_per_day
case movie_type
@graemeboy
graemeboy / 2d-matrix-search.js
Created March 7, 2015 23:43
2D Ordered Matrix Search
var matrix = [
[1, 1, 1, 2, 2, 3],
[2, 3, 3, 4, 4, 6],
[3, 5, 6, 6, 7, 7],
[4, 5, 6, 6, 8, 8],
[5, 7, 7, 8, 8, 9]
];
var target = 6; // We’re going to try find the position of 6 in the array
@graemeboy
graemeboy / string-permutations.js
Created February 23, 2015 03:48
String Permutations
function combineChars (chars) {
var permutations = [], words = [], firstChar;
if (chars.length === 1) { // base case
permutations.push(chars);
return permutations;
}
firstChar = chars[0];
chars = chars.substring(1,chars.length);
words = combineChars(chars);
for (var i = 0; i < words.length; i++) {
@graemeboy
graemeboy / standby-button.css
Created February 22, 2015 04:41
Standby Logout Button CSS
.exit-btn:after {
content: '';
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.exit-btn {
border: none;
@graemeboy
graemeboy / blue-logout-button.css
Created February 22, 2015 04:40
Blue Logout Button CSS
.exit-btn:after {
content: '';
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.exit-btn {
border: none;
@graemeboy
graemeboy / purple-button.css
Created February 22, 2015 04:39
Purple Button CSS
.exit-btn:after {
content: '';
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.exit-btn {
border: none;
@graemeboy
graemeboy / round-logout-button.css
Created February 22, 2015 04:36
Round Logout Button
.exit-btn:after {
content: '';
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.exit-btn {
border: none;