Skip to content

Instantly share code, notes, and snippets.

<?php
class Functions {
public static function getScope() {
// Here I had to instantiate the class twice, or the static method would not be callable (???)
return ['Functions\Inner' => new \Functions\Inner((new \Function\Inner([]))::getScope()) ];
}
public function __construct($scope) {
if ($scope !== []) {
$this->scope = $scope;
// Generated by purs version 0.13.8
"use strict";
var bar2 = 3;
var bar1 = function (x) {
return x;
};
module.exports = {
bar1: bar1
};
-- Halogen 4
data State = { started :: Boolean, choice :: String }
data Query = Start | Choose String
component :: Monad m => H.Component HH.HTML Query Unit Void m
component =
H.component
{ initialState: const { started: false, choice: "" }
#! /usr/bin/env nix-shell
#! nix-shell -p haskellPackages.ghcid
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [req casing comonad])"
#! nix-shell -i "ghcid -W -c 'ghci -Wall' -T main"
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
-- first I want to select some elements to display in my table
select $ from $ \(foo `innerJoin` bar) -> do
on (foo ^. FooBar ==. bar ^. BarId)
where_ (foo ^. FooFoo ==. E.val True)
orderBy [asc (foo ^. FooId)]
offset (resultsPerPage * pageNum)
limit resultsPerPage
pure (foo, bar)
-- then I want to count the total to know how many pages are there
type MyRecord = { foo :: String, bar :: Instant }
decodeinsomeway :: Int -> Either String Instant
decodeinsomeway i = eitherturnintintoinstantornot i
decodeMyRecord :: Json -> Either String MyRecord
decodeMyRecord json = do
tempRecord <- decodeJson json -- this is decoded as { foo :: String, bar :: Int }
newField <- decodeinsomeway tempRecord.bar
pure $ tempRecord { bar = newField }
...
postFile :: forall b. ReadForeign b => URL -> FormData -> Aff (E b)
postFile url content = do
cookie <- liftEffect getXSRFToken
defaultRequest' <- sDefaultRequest
let req = Record.merge defaultRequest' defaultRequest
req' = Record.delete (SProxy :: SProxy "retryPolicy") req
res <- try $ request $ req' { method = Left POST
, url = url
, content = Just $ RequestBody.formData content
module Components.Form.Search where
import Prelude
import Bulma as B
import Component.Utils.Debounced (DebounceTrigger, cancelDebounceTrigger, debouncedEventSource, runDebounceTrigger)
import Data.Foldable (for_)
import Data.Maybe (Maybe(..))
import Data.String (length, null)
import Effect.Aff (Aff, Milliseconds)
module Component.Utils.Debounced where
import Prelude
import Data.Either as E
import Data.Foldable (traverse_)
import Data.Maybe (Maybe(..))
import Effect.Aff.AVar as AVar
import Effect.Aff (Milliseconds, delay, forkAff, killFiber)
import Effect.Aff.Class (class MonadAff, liftAff)
-- let's ignore negative inputs
sub1 :: Int -> Int
sub1 0 = throw $ SomeException 0
sub1 n = n - 1
countDown :: Int -> IO Int
countDown n = countDown (sub1 n) `catch` \(SomeException n') -> pure n'