Skip to content

Instantly share code, notes, and snippets.

View paulghaddad's full-sized avatar

Paul Haddad paulghaddad

View GitHub Profile
@paulghaddad
paulghaddad / gist:a52a514734a2746e19eb
Last active August 29, 2015 14:13
LevelUp 6: Creates humane APIs, and understands that everything has an API
1. Explain what it means that 'everything has an API'.
"Everything has an API" is the notion that an API is more than the common usage of an interface to produce and consume data between two web services. APIs also exist within programs, gems, libraries, and classes, among other constructs. An API is the interface that defines how any two software programs interact. This could, for example, be between a Ruby Gem and the Ruby Array library. When the Ruby gem calls #sort on an Array object, it is interacting with the API of the Array library. In object-oriented programming, the core concept is that messages are passed between objects; it is the API that defines the boundaries of those objects and how they interact. APIs exist everywhere in programming, from the common usage of a web application API, such as the Google Maps API, to the many Rails APIs to the API of a small program.
@paulghaddad
paulghaddad / README.md
Created January 7, 2015 18:08
Exercism: Roman Numerals

Roman Numerals

Write a function to convert from normal numbers to Roman Numerals: e.g.

The Romans were a clever bunch. They conquered most of Europe and ruled it for hundreds of years. They invented concrete and straight roads and even bikinis. One thing they never discovered though was the number zero. This made writing and dating extensive histories of their exploits slightly more challenging, but the system of numbers they came up with is still in use today. For example the BBC uses Roman numerals to date

@paulghaddad
paulghaddad / gist:693c3fa016fed563fcab
Created January 5, 2015 21:41
LevelUp 4: Knows the location and conventions for Rspec and Cucumber
Exercise: Knows the location and conventions for Rspec and Cucumber
3. Explain the usage of integration versus unit tests in your Rails app.
Integration tests in a Rails app will test the functionality of an entire Feature. This will normally test the entire response cycle--from the initial request, to the controller, models, views and then the response returned to the browser. Unit tests, in contrast, focus on testing one method or interaction in one particular class in the app. This could be a model, helper, controller or view. They are much more focused than integration tests.
4. There is a default command that is used in normal Rails codebases to run all tests. What is it?
"rake" will run all tests
"rake spec" will run all tests in the spec directory
@paulghaddad
paulghaddad / gist:bfaec3b270cfe7592942
Created January 5, 2015 20:56
LevelUp 4: Knows how to list and run rake tasks, and what things should be rake tasks
1. Demonstrate the command to list all the rake tasks, and the one to match a particular set of tasks.
rake -T
2. Explain what sorts of tasks (including examples) belong in a rake task.
Tasks that belong in a rake task include jobs that should be performed on the command line, and not through the UI. Administrative tasks involving assets, the database, documentation, routes, temporary files, and performing batch processes, such as updating database records or sending out emails, are all viable rake tasks.
@paulghaddad
paulghaddad / gist:c38d8c2a437e1eccafc6
Created January 5, 2015 20:23
LevelUp 4: Knows how to use view helpers to aid clarity
1. Explain how helpers improve the readability and organization of your rails app.
View helpers allow you to extract logic from your views in order to keep them as simple as possible. They improve the readability of view templates in several ways:
- Replacing complicated logic with a call to a helper method eliminates a lot of code from the view template itself. In addition, the code that remains in the view template is focused on the view layer, namely HTML elements and ERB tags consisting of calls to view helpers and objects from the controller.
- The purpose of the view helper can be expressed by the name you choose. For example, a view helper that displays admin controls can be encapsulated in a method named, "admin_controls". The purpose of the method is clear from its name. If you instead put all the logic to determine whether a user is an admin and then conditionally display elements, the purpose of the code would be difficult to comprehend.
In addition to making the view templates easier to read,
@paulghaddad
paulghaddad / README.md
Created December 17, 2014 17:48
difference_of_squares.rb

Difference Of Squares

Find the difference between the sum of the squares and the square of the sums of the first N natural numbers.

The sum of the squares of the first ten natural numbers is,

1**2 + 2**2 + ... + 10**2 = 385

The square of the sum of the first ten natural numbers is,

@paulghaddad
paulghaddad / raindrops.rb
Last active August 29, 2015 14:10
Exercism: Raindrops
########## Raindrops Exercism Problem ##############
class Raindrops
class << self
def convert(number)
add_sounds(number) || number.to_s
end
private
@paulghaddad
paulghaddad / complement.rb
Last active August 29, 2015 14:10
Exercism: RNA Transcription
module Complement
DNA_TO_RNA_MAP = {
'A' => 'U',
'C' => 'G',
'G' => 'C',
'T' => 'A'
}
RNA_TO_DNA_MAP = DNA_TO_RNA_MAP.invert
@paulghaddad
paulghaddad / gigasecond.rb
Last active August 29, 2015 14:10
Exercism: Gigasecond
require 'date'
require 'time'
class Gigasecond
GIGASECONDs_IN_DAYS = 10**9 / (60 * 60 * 24) # 1 day = 86,400 seconds
def self.from(date)
date + GIGASECONDs_IN_DAYS
end
@paulghaddad
paulghaddad / hamming.rb
Last active August 29, 2015 14:10
Exercism: Hamming
####### Submission for Hamming Exercism Problem #########
class Hamming
def self.compute(strand, comparison_strand)
return 0 if strand == comparison_strand
strand_array = strand.split(//)
comparison_strand_array = comparison_strand.split(//)
compute_difference(strand_array, comparison_strand_array)
end
def self.compute_difference(strand_1, strand_2)