This file contains 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 ProcessesInElixirTest do | |
use ExUnit.Case | |
import ExUnit.CaptureIO | |
test "handles {:print_success} properly" do | |
pid = spawn(ProcessesInElixir, :loop, []) | |
assert capture_io(fn -> | |
send pid, {:print_success} | |
end) | |
buffer == "Feet" |
This file contains 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 ProcessesInElixirTest do | |
use ExUnit.Case | |
import ExUnit.CaptureIO | |
test "handles {:print_success} properly" do | |
pid = spawn(ProcessesInElixir, :loop, []) | |
assert capture_io(fn -> | |
send pid, {:print_success} | |
end) == "Success!" | |
end |
This file contains 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 GenIncrement do | |
use GenServer | |
# Public | |
def start_link do | |
# GenServer.start_link(GenIncrement, [], name: __MODULE__) | |
{:ok, pid} = GenServer.start_link(GenIncrement, []) | |
Process.register(pid, __MODULE__) | |
{:ok, pid} | |
end |
This file contains 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
# call run on a object that has | |
# a #call method | |
# takes one argument | |
# and returns an array with [status_code, headers, body] | |
require 'pry' | |
class App | |
def call(env) | |
binding.pry | |
request = Rack::Request.new(env) |
This file contains 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
curl https://gist.githubusercontent.com/StevenNunez/1df2da72168f9c33abe3/raw/81abd03d0acfc696fb3a358f964d7bc1201175cd/seed.sql > seed.sql | |
sqlite3 chinook.db -init seed.sql -cmd .tables |
This file contains 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
curl https://gist.githubusercontent.com/StevenNunez/1df2da72168f9c33abe3/raw/81abd03d0acfc696fb3a358f964d7bc1201175cd/seed.sql > seed.sql | |
sqlite3 test.db -init seed.sql -cmd .tables |
This file contains 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 Person | |
attr_reader :name # => nil | |
def initialize(name) | |
@name = name # => "Bob" | |
end | |
def to_s | |
"Hi, My name is chicka chicka #{name}" # => "Hi, My name is chicka chicka Bob" | |
end | |
end |
This file contains 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 Person | |
attr_reader :name # => nil | |
puts self # => nil | |
def initialize(name) | |
@name = name # => "Bob" | |
end | |
# def self.new | |
# instance = self.allocate | |
# instance.initialize |
This file contains 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
1.odd? # => true | |
1 + 1 # => 2 | |
1.+(1) # => 2 | |
1.send(:odd?) # => true | |
names = ["Steven", "Sophie", "Antoin"] # => ["Steven", "Sophie", "Antoin"] | |
names[0] # => "Steven" | |
names.[](0) # => "Steven" | |
steven = {name: "Steven"} # => {:name=>"Steven"} | |
steven[:name] # => "Steven" | |
steven.[](:name) # => "Steven" |
This file contains 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 'rest-client' | |
require 'json' | |
result = RestClient.get("http://reddit.com/.json") | |
result_hash = JSON.parse(result) | |
puts result_hash | |
puts "The return value from Restclient is a #{result.class}" | |
puts "The return value from JSON.parse is #{result_hash.class}" |