Skip to content

Instantly share code, notes, and snippets.

require 'dry-validation'
## Schema
Users::NewSchema = Dry::Validation.Form do
GENDERS = %w(
male
female
non-specific
)
require 'dry-validation'
schema = Dry::Validation.Schema do
GENDERS = %w(
male
female
non-specific
)
required(:email).filled(:str?)
module Order
# Service Object used to transit order into checkout state
class CheckoutOrderService
def initialize(order)
@order = order
end
def call
validate_order!
class ClassWithModule
include ModuleExample
end
# Abstract calculator class, only for inheritance
class Calculator
def calculate
raise NotImplementedError, 'must be implemented in subclass'
end
end
@azranel
azranel / fizzbuz.rb
Created August 5, 2017 14:22
FizzBuzz non-opp
def fizzbuzz(number)
if (number % 3 == 0 && number % 5 ==0)
puts "FizzBuzz"
elsif (number % 3 == 0)
puts "Fizz"
elsif (number % 5 == 0)
puts "Buzz"
else
puts number
end
defmodule SomeApp.Router do
use SomeApp.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
defmodule SomeApp.Endpoint do
use Phoenix.Endpoint, otp_app: :some_app
socket "/socket", SomeApp.UserSocket
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
defmodule BlogPostApp.Post do
use BlogPostApp.Web, :model
schema "posts" do
field :name, :string
field :content, :string
field :published, :boolean, default: false
timestamps()
end
defmodule BlogPostApp.Repo.Migrations.CreatePost do
use Ecto.Migration
def change do
create table(:posts) do
add :name, :string
add :content, :text
add :published, :boolean, default: false, null: false
timestamps()