Skip to content

Instantly share code, notes, and snippets.

@mightybyte
mightybyte / DateFormlets.hs
Created December 10, 2013 19:04
A collection of core date/time formlets for digestive-functors.
utcTimeFormlet :: Monad m
=> String
-- ^ Date format string
-> String
-- ^ Time format string
-> TimeZone
-> Formlet Text m UTCTime
utcTimeFormlet dFmt tFmt tz d =
localTimeToUTC tz <$> localTimeFormlet dFmt tFmt (utcToLocalTime tz <$> d)
@mightybyte
mightybyte / gist:3f7dfd8b20b45bdc9dd9
Last active August 29, 2015 14:02
TODO list for snap and heist 1.0
  • Move Heist.SpliceAPI to map-syntax (https://github.com/mightybyte/map-syntax)

  • Add namespace support to heist

    This means that users will be able to specify a namespace under which Heist will operate. If the user specifies a namespace of "h", then the splice '"foo" ## fooSplice' will match the tag <h:foo>. This alone doesn't give us much benefit. But on top of that we will add checking so Heist will throw an error if it encounters any <h:...> tag that does not have a splice bound for it. This will be a big help in finding bugs caused by not having a splice bound.

@mightybyte
mightybyte / gist:2472faa614fde892afae
Last active August 29, 2015 14:17
diagrams metafont problem
-- image: http://i.imgur.com/567RLZ2.png
squiggle :: Path V2 Double
squiggle = rotate ((-1)/4 @@ turn) $ metafont $
(4 ^& 1) .--.
(10 ^& 4) .--.
(15 ^& 5.2) .--.
(20 ^& 5) .--.
(25 ^& 3) .--.
(30 ^& 1.5) .--.
@mightybyte
mightybyte / Main.hs
Last active March 20, 2018 05:50
Attaching reflex to a particular node
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
------------------------------------------------------------------------------
import Control.Concurrent
import Control.Monad
import Control.Monad.Trans

Keybase proof

I hereby claim:

  • I am mightybyte on github.
  • I am mightybyte (https://keybase.io/mightybyte) on keybase.
  • I have a public key whose fingerprint is E354 4097 9E03 BC59 CC6F 444A 0272 6879 EA3E 9B28

To claim this, I am signing this object:

@mightybyte
mightybyte / WidgetTypes.hs
Last active May 30, 2017 22:09
FRP Widgets
data WidgetConfig t a
= WidgetConfig { _widgetConfig_setValue :: Event t a
, _widgetConfig_initialValue :: a
, _widgetConfig_attributes :: Dynamic t (Map String String)
}
makeLenses ''WidgetConfig
instance (Reflex t, Default a) => Default (WidgetConfig t a) where
def = WidgetConfig { _widgetConfig_setValue = never
@mightybyte
mightybyte / gist:753e2d5dea800b2eb0cc
Last active August 29, 2015 14:27
gen-bounds output
$ dist/build/cabal/cabal gen-bounds
Resolving dependencies...
The following packages need bounds and here is a suggested starting point.
You can copy and paste this into the build-depends section in your .cabal
file and it should work (with the appropriate removal of commas).
Note that version bounds are a statement that you've successfully built and
tested your package and expect it to work with any of the specified package
versions (PROVIDED that those packages continue to conform with the PVP).
@mightybyte
mightybyte / location.hs
Created September 29, 2015 17:40
Reflex Location Management
------------------------------------------------------------------------------
-- | Gets the current path of the DOM Window (i.e., the contents of the
-- address bar after the host, beginning with a "/").
-- https://developer.mozilla.org/en-US/docs/Web/API/Location
getWindowLocationPathname :: DOMWindow -> IO String
#ifdef ghcjs_HOST_OS
getWindowLocationPathname w = do
jw <- toJSRef w
liftM fromJSString $ js_windowLocationPathname jw
@mightybyte
mightybyte / reflex-hilbert-diagram.hs
Last active February 5, 2016 21:15
Diagrams example snippet
app :: MonadWidget t m => App t m ()
app = do
ti <- textInput $ TextInputConfig "range" "4" never
(constDyn $ "min" =: "1" <> "max" =: "6")
n <- holdDyn (4::Int) (read <$> updated (value ti))
let f = reflexDia (def & sizeSpec .~ D.mkSizeSpec2D (Just 600) (Just 600)) . example
el "div" $ widgetHoldHelper f 4 (updated n)
return ()
hilbert 0 = mempty
@mightybyte
mightybyte / gist:ae26c9b9d7bef0419b0f
Last active November 13, 2015 18:45
Get all of a function's arguments and return value
getArgs :: Type -> [Type]
getArgs (ForallT _ _ t) = getArgs t
getArgs (SigT t _) = getArgs t
getArgs (AppT (AppT ArrowT a) b) = a : getArgs b
getArgs b = [b]
-- Possible lens version
prismCase [ _ForallT . _3 :-> getArgs, _SigT . _1 :-> getArgs, _AppAppArrow :-> \(a,b) -> a : getArgs b, id :-> \b -> [b] ]