Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View joeletizia's full-sized avatar

Joe Letizia joeletizia

View GitHub Profile
defmodule Success do
@type t :: %Success{value: any}
defstruct value: nil
end
defmodule Failure do
@type t :: %Failure{value: any, reason: String.t}
defstruct value: nil, reason: nil
end
defmodule EmailValidation do
def validate(email) do
email_validation_result = {:ok, email}
check_for_validity(email_validation_result)
|> check_if_email_taken
end
defp check_for_validity({:ok, email}) do
case check_against_regex(email) do
Dir.glob("**/*.rb").each do |file|
`vim -c "set ts=4 sts=4 noet|retab!|set ts=2 sts=2 et|retab|wq" #{file}`
end
@joeletizia
joeletizia / products.rb
Created December 15, 2015 22:21
Controller resources that are agnostic of content type to be rendered.
module Products
# What if we want to differ the content between iOS and Web?
class IndexResource
def initialize(product_presenters, content_type)
@product_presenters = product_presenters
@content_type = content_type
end
def render(rendering_engine = RenderingEngine)
rendering_engine.render(partial_path, product_presenters: product_presenters)
@joeletizia
joeletizia / products.rb
Created December 15, 2015 22:21
Controller resources that are agnostic of content type to be rendered.
module Products
# What if we want to differ the content between iOS and Web?
class IndexResource
def initialize(product_presenters, content_type)
@product_presenters = product_presenters
@content_type = content_type
end
def render(rendering_engine = RenderingEngine)
rendering_engine.render(partial_path, product_presenters: product_presenters)
@joeletizia
joeletizia / homework.md
Created July 31, 2015 14:19
Dakarai Homework 2

Dakarai Homework #2

  1. Write a function called stop_sign that prints out the question Which way do you want to turn? and then takes keyboard input from the user. If the input equals left print Turning left!. If the input equals right print Turning right!. If the input is anything other than the two previous options, print Crash!!!
  2. Write a function called spaces that takes a string as input. Return the number or spaces in the string as an integer.
@joeletizia
joeletizia / assignment.md
Last active August 29, 2015 14:25
Dakarai Homework

Write the following functions

  1. A function named dog that prints out "Woof!" to the screen.
  2. A function named cat that prints out "Meow." to the screen.
  3. A function named hello_name that takes a string as input and prints out "Hello, name!" where name is the string given as input.
  4. A function named even? that takes a number as input and returns true if the number is evenly divisibly by 2 and false otherwise.
  5. A function named multiple_of? that takes 2 inputs. For example: multiple_of?(2, 4) returns true because 4 is a multiple of 2 (2*2 = 4). multiple_of?(5, 32) returns false because 32 is not a multiple of 5.
  6. A function named count that takes a number as input and prints out all the numbers between 0 and number to the screen.
  7. A function named multiples that takes a number as input, and returns an array containing all results of the given number multiplied by the numbers from 1 to 10. So for multiples(5) the result should be [5,10,15,20,25, ...]
@joeletizia
joeletizia / tmux.sh
Created July 8, 2015 13:46
How to startup up tmux with a partner
# On the host machine, run
tmux -S /tmp/foo
chmod 777 /tmp/foo
# From the remote machine
ssh username@host
tmux -S /tmp/foo attach
@joeletizia
joeletizia / clicker-alert.js
Created April 22, 2014 15:56
Elemental / Data Presents Pattern
presenters.ClickerAlert = function(element) {
$(element).on('click', showAlert);
function showAlert(){
alert("Hey, you clicked me!");
}
}
(function($, ns) {
ns('clicker-alert', {
@joeletizia
joeletizia / example.rb
Created June 26, 2013 01:54
Example of mocking and stubing with dependency injection
module Example
class Dog
attr_reader :stomach
def initialize(stomach)
@stomach = stomach
end
def hungry?
stomach.empty?