This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Db do | |
use GenServer.Behaviour | |
## API | |
def start() do | |
:gen_server.start({:local, :db}, __MODULE__, [], []) | |
end | |
def store(key, val) do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
anwer(foo, Args) -> % pattern match the arguments | |
answer_to_foo; % notice the semi-colon | |
answer(bar, Args) -> | |
case Delicious of | |
veggies -> | |
false; % Again, notice the semi colon | |
bacon -> % case is another form of pattern matching | |
true % The last statement in the case has no punctuation | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
change(Amount) -> % => Binding 2 x 1 | |
{Coins, _} = lists:foldl(fun(Denom, {Coins, Total}) -> % => Invocation 2 x 1, Binding 4 x 1, Constant 1 x 1 | |
Floor = floor(Total / Denom), % => Binding 1 x 1, Invocation 2 x 2 | |
{Coins ++ lists:duplicate(Floor, Denom), Total - (Floor * Denom)} % => Invocation 2 x 4 | |
end, {[], Amount}, [25, 10, 5, 1]), % => Constant 2 x 1 | |
Coins. | |
% Total = 2 + 2 + 4 + 1 + 1 + 4 + 8 + 2 = 24 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'timer' | |
unless defined?(REQUIRED_SPEC_HELPER) | |
REQUIRED_SPEC_HELPER = true | |
File.open("spec_helper_times.yml", 'a+') do |file| | |
date_time = DateTime.now.strftime("%m%d%y%H%M") | |
time = Time.now | |
Kernel.load("spec_helper.rb", true) | |
final_time = Time.now - time | |
file << "#{date_time}: #{final_time}\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MMMM MMM | |
MM: 8M MMM$I7 | |
MM: OM MMM7I7MM | |
MM, $M MMD7IIDMM | |
MM, 7M MM8III8M | |
MO. ?MM MMOIIIOM | |
M$ =MM MMMZIIIZMM | |
M7 =MM MMM$III$MM | |
MM? :MM MMM7III7MM | |
MM+ :MM MMN7III7M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### We are highlighting a workflow to retrieve Employees who | |
### have the title of department leaders. | |
### The web entry point comes through the controller, | |
### but it's important for the controller to have no logic. | |
### It simply knows that it must call the department leaders | |
### method on the interactor. | |
class EmployeeController < ApplicationController | |
def get_department_leaders | |
leaders = Interactor::Employees.get_deparment_leaders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Reader | |
def read | |
file = File.new("readfile.rb", "r") | |
return file.gets | |
end | |
end | |
class Writer | |
def write(chars) | |
file = File.new("readfile.rb", "w") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Reader | |
def read | |
return get.chomp() | |
end | |
end | |
class Writer | |
def write(chars) | |
puts chars | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Message.java **/ | |
public interface Message { | |
public void sayIt(); | |
} | |
/** HelloWorld.java **/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
class Bar | |
end | |
class Baz | |
def gen_bar |