Skip to content

Instantly share code, notes, and snippets.

Avatar

Karlo Smid karlosmid

View GitHub Profile
View picshare_working_comment.elm
module Picshare exposing (main)
import Browser
import Html exposing (..)
-- 2. add onInput and onSubmit
import Html.Events exposing (onClick, onInput, onSubmit)
-- 1. add disabled and value
import Html.Attributes exposing (class, src, placeholder, type_, disabled, value)
type alias Model =
{ url : String
, caption : String
@karlosmid
karlosmid / if_macro.ex
Last active Oct 24, 2020
example of using elixir macros
View if_macro.ex
defmodule If do
defmacro if(clause, do: expression) do
quote do
if(unquote(clause) == :true, do: unquote(expression))
end
end
end
@karlosmid
karlosmid / picshare_display_comment.elm
Created Oct 18, 2020
Picshare elm application now displays comments
View picshare_display_comment.elm
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 Oct 23, 2020
Introduction to software testing section 1.2
View faulty_programs.ex
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.
View picshare_business_logic.elm
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 Oct 5, 2020
Pichare application refactored using type alias
View picshare_type_alias.elm
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
View picshare_with_like.elm
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 =
View picshare_update_method.elm
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 []
View pickshare_with_like_button.elm
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 Jul 13, 2020
Phoenix Swagger validation in production
View application.ex
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.
You can’t perform that action at this time.