Skip to content

Instantly share code, notes, and snippets.

View paulcsmith's full-sized avatar

Paul Smith paulcsmith

View GitHub Profile
@paulcsmith
paulcsmith / cheat_sheet.md
Last active September 22, 2015 20:42
ExMachina Cheat Sheet - v0.3.0
  • factory(factory_name) to define a factory
factory(:user) do
  %User{name: "John"}
end
  • create(:user, name: "Jane")
  • build(:user, name: "Jane")
  • assoc(:author, factory: :user) (can only be used inside factory definition)
@paulcsmith
paulcsmith / factory.ex
Last active October 12, 2015 22:42
Defining factories in ExMachina. Some ideas
# This is a bit more flexible. Worried people will try to call it directly :S
# Also throws warnings if you put functions in between the function definitions
def factory(:user, attrs) do
%User{
first_name: "Paul" ,
last_name: "Smith"
email: put_new_email(attrs)
}
end
defmodule MyApp.Factory do
use ExMachina.Ecto, repo: MyApp.Repo
def factory(:interest, attrs) do
%Interest{
name: sequence(:interest_name, &"interest-#{&1}")
}
end
def factory(:user, attrs) do
defmodule MyApp.AnnouncementTraits do
def with_subscriber(announcement, user) do
create(:subscription, announcement: announcement, user: user)
announcement
end
def tag_with_interest(announcement, interest) do
create(:announcement_interest, announcement: announcement, interest: interest)
announcement
end
Bypass fake_stripe do
get "soemthing" do
send_resp conn, ""
end
end
@paulcsmith
paulcsmith / gist:7472916
Created November 14, 2013 19:34
My key bindings for pairing with someone using VIM
" Type jj in insert mode to escape to command mode
:imap jj <Esc>
" Type j; in insert mode to escape to command mode with a : already typed
:imap j; <Esc>:
" Type ;w in insert mode to escape to command mode with :w already typed
:imap ;w <Esc>:w
" Use semicolon instead of colon. Don't have to hit shift now
map ; :
module Colleague::Classes
class CitizenshipStatus
include Processor
def process_field(value)
AlienStatus.find_code( value )
end
end
end
@paulcsmith
paulcsmith / resources.md
Last active January 20, 2016 17:02
Helpful Resources for learning Elixir/Ecto/Phoenix

Books & in depth resources

  • Phoenix Guides - This is one the best ways to get started. The guides cover most of the fundamental topics and explain the ins and outs of how Phoenix works. I would start here and look up the parts of Elixir you don't understand as you go.
  • Programming Phoenix - Still in beta, but very well done. I would recommend getting it even while in beta. It has a brief introduction to Elixir and covers all the important concepts in Phoenix
  • Elixir Getting Started Guide - This is the official Elixir getting started guide. You don't need to know everything here to get started, but it covers a lot of fundamentals in sections 1-21.

Specific Phoenix Guides that are very helpful

@paulcsmith
paulcsmith / bamboo_assertions.ex
Created January 23, 2016 03:15
Bamboo assert_email_delivered/1 function
# Something like this might make testing simpler
def assert_email_delivered(email) do
email = email |> Bamboo.Mailer.normalize_addresses
assert_received({:delivered_bamboo_email, ^email})
end
@paulcsmith
paulcsmith / layout.html.eex
Last active January 29, 2016 03:59
Render title and meta tags in Phoenix
<head>
<!-- you could put a helper in the Layout View but it's probably not necessary -->
<%= render_existing(@view_module, "seo." <> @view_template, assigns) || render("default_seo.html") %>
</head>