Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env stack
-- stack runghc --resolver lts-9.14 --install-ghc --package mtl
{-# LANGUAGE CPP #-}
import Control.Monad.Trans.Maybe (MaybeT(MaybeT), runMaybeT)
import Control.Monad.Trans.Except (ExceptT(ExceptT), runExceptT)
import System.Environment (lookupEnv)

Persistent

Persistent does make use TH, but it only requires you to use it as a consumer. That is: you define your schema using its DSL, and then it generates your migrations, data types, instances, etc. for you (which uses TH under the hood).

Schema

To give you an idea of what to expect, here's a psuedo-code version of a schema definition:

#!/usr/bin/env ruby
require 'pathname'
require 'uri'
module HTML
def table(txt)
node('table', txt)
end
#!/usr/bin/env ruby
require 'pathname'
require 'uri'
module HTML
def table(txt)
node('table', txt)
end
#!/usr/bin/env ruby
require 'pathname'
module HTML
def table(txt)
node('table', txt)
end
#!/usr/bin/env ruby
require 'sinatra'
set :port, ENV['PORT'] || 8080
get '*/elm.js' do |_|
send_file 'dist/elm.js'
end
module AoC201704A exposing (..)
a1 : List String -> Int
a1 lines =
let
valid : String -> Bool
valid passphrase =
List.length (S.split " " passphrase) == List.length (L.unique (S.split " " passphrase))
in
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Aedict where
import Data.Maybe (maybe)
import Text.Regex.PCRE.Heavy
defmodule Foo do
def crash_unless_password(pw) do
"password" = pw
IO.puts "I didn't crash!"
end
def validate_v1(token) do
case token do
"tok_" <> _ ->
IO.puts "Valid token `#{token}!`"
# INSTALL -- ERLANG & ELIXIR
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get install erlang erlang-dev elixir
# INSTALL -- HEX, PHOENIX, & NODE 6.X
mix local.hex
mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez