Skip to content

Instantly share code, notes, and snippets.

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"
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
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
# 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)
curl https://gist.githubusercontent.com/StevenNunez/1df2da72168f9c33abe3/raw/81abd03d0acfc696fb3a358f964d7bc1201175cd/seed.sql > seed.sql
sqlite3 chinook.db -init seed.sql -cmd .tables
curl https://gist.githubusercontent.com/StevenNunez/1df2da72168f9c33abe3/raw/81abd03d0acfc696fb3a358f964d7bc1201175cd/seed.sql > seed.sql
sqlite3 test.db -init seed.sql -cmd .tables
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
class Person
attr_reader :name # => nil
puts self # => nil
def initialize(name)
@name = name # => "Bob"
end
# def self.new
# instance = self.allocate
# instance.initialize
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"
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}"