Skip to content

Instantly share code, notes, and snippets.

View ptkato's full-sized avatar
💖
Haskelling

ptkato

💖
Haskelling
View GitHub Profile
@ptkato
ptkato / Foundation.hs
Created January 22, 2021 17:30
Foundation.hs example
module Foundation where
import Yesod
import Yesod.Static
import Yesod.Auth
import Yesod.Auth.Email as YAE
import Yesod.Auth.GoogleEmail2 as GE2
import Yesod.Auth.Facebook.ServerSide as YAF
import Yesod.Facebook
import Control.Applicative ((<$>), (<*>))
@ptkato
ptkato / snippet.hs
Last active November 13, 2017 13:02
runDB $ do
prods <- selectList [] []
forns <- mapM (get . produtoFornecedorId . entityVal) prods
return . zip prods $ catMaybes forns
patchAgendamento :: Handler Value
patchAgendamento = do
horarioNovo <- requireJsonBody :: Handler UTCTime
valores <- runDB $ selectList [] [Asc AgendamentoHorario]
runDB $ mapM_ (\chave -> update chave [AgendamentoHorario =. hoarioNovo]) valores
sendStatusJSON noContent204 $ object emptyObject
@ptkato
ptkato / snippet.js
Last active February 27, 2016 03:34
A thing.
alunos = [{nome:"Nilmar",notas:[2.5,6,6]},{nome:"Gustavo",notas:[6,4.5,7]},{nome:"Alexandre",notas:[10,10,0]},{nome:"Lionel Messi",notas:[5.9,5.9,5.9]}]
aprovados = alunos.filter(function(x) {
return (x.notas.sort(function(a, b) {
return a - b;
}).splice(0, 2).reduce(function(y, z) {
return y + z;
}) / 2) >= 6;
});
console.log(aprovados);
formAv :: Form Avaliacao
formAv = renderDivs $ Avaliacao <$>
areq intField "Nota" Nothing <*>
pure kludge <*>
areq (selectField lv) "Livro:" Nothing <*>
areq textField "Avaliação: " Nothing
kludge = case us of
Just (Entity pid user) -> pid
Nothing -> redirect LoginR