Skip to content

Instantly share code, notes, and snippets.

View karlosmid's full-sized avatar

Karlo Smid karlosmid

View GitHub Profile
@karlosmid
karlosmid / picshare_display_comment.elm
Created October 18, 2020 11:20
Picshare elm application now displays comments
module Picshare exposing (main)
import Browser
import Html exposing (..)
import Html.Events exposing (onClick)
-- 3. expose from Html.Attributes modeul placeholder and type_ functions
import Html.Attributes exposing (class, src, placeholder, type_)
type alias Model =
{ url : String
, caption : String
, liked : Bool
@karlosmid
karlosmid / faulty_programs.ex
Last active October 23, 2020 12:55
Introduction to software testing section 1.2
defmodule IntroToSoftwareTesting.FaultyPrograms do
@moduledoc """
Supports exercises from the book Introduction To Sofware Testing, section 1.2
"""
@doc """
findLast returns index of last element in x list that is equal to y.
If there is no such element, returns -1
"""
@doc """
findLast returns index of last element in x list that is equal to y.
module Picshare exposing (main)
import Browser
import Html exposing (..)
import Html.Events exposing (onClick)
import Html.Attributes exposing (class, src)
type alias Model =
{ url : String
, caption : String
, liked : Bool
}
@karlosmid
karlosmid / picshare_type_alias.elm
Created October 5, 2020 12:38
Pichare application refactored using type alias
module Picshare exposing (main)
import Browser
import Html exposing (..)
import Html.Events exposing (onClick)
import Html.Attributes exposing (class, src)
-- 1. type alias for our record model
type alias Model =
{ url : String
, caption : String
, liked : Bool
@karlosmid
karlosmid / picshare_with_like.elm
Created September 23, 2020 10:58
elm picshare program
module Picshare exposing (main)
-- 1. we need Browser module
import Browser
import Html exposing (..)
import Html.Events exposing (onClick)
import Html.Attributes exposing (class, src)
-- 2. rewrite main annotation type
main : Program () {url: String, caption: String, liked: Bool } Msg
-- 3. and main constant
main =
module Picshare exposing (main)
import Html exposing (..)
import Html.Events exposing (onClick)
import Html.Attributes exposing (class, src)
main : Html Msg
main =
view initialModel
view : { url : String, caption : String, liked: Bool } -> Html Msg
view model =
div []
module Picshare exposing (main)
import Html exposing (..)
-- 8. import Events module
import Html.Events exposing (onClick)
import Html.Attributes exposing (class, src)
-- 10 . msg => Msg
main : Html Msg
main =
view initialModel
-- 2. change view function annotation by adding liked and changing msg => Msg type
@karlosmid
karlosmid / application.ex
Created July 13, 2020 06:48
Phoenix Swagger validation in production
def start(_type, _args) do
if Application.fetch_env!(:your_app_name, :production) do
PhoenixSwagger.Validator.parse_swagger_schema(
Path.join(["#{:code.priv_dir(:your_app_name)}", "static", "swagger.json"])
)
else
PhoenixSwagger.Validator.parse_swagger_schema("priv/static/swagger.json")
end
// ... rest of your Phoenix Application start up code.
defmodule Testivator.CRM.DatafileSpec do
@moduledoc """
This module holds espec spec demonstrations for CRM.Datafile module.
"""
use ESpec.Phoenix, async: false, model: DataFile
alias Testivator.CRM.DataFile
alias Testivator.File
import Mock
context "Changeset" do
defmodule Testivator.CRM.DataFile do
@moduledoc """
DataFile schema
"""
use Testivator.Web, :model
use Arc.Ecto.Schema
alias Testivator.CRM.Charter
alias Testivator.CRM.DataFile
schema "datafiles" do