Skip to content

Instantly share code, notes, and snippets.

@mightybyte
mightybyte / clock.patch
Created December 18, 2015 00:06
diff -r clock-0.5.1 clock-0.5.2
diff -r clock-0.5.1/System/Clock.hsc clock-0.5.2/System/Clock.hsc
173,177c173,175
< normalize (TimeSpec xs xn)
< | xn < 0 || xn >= 10^9 =
< let (q, r) = xn `divMod` (10^9)
< in TimeSpec (xs + q) r
< | otherwise = TimeSpec xs xn
---
> normalize (TimeSpec xs xn) | xn < 0 || xn >= 10^9 = TimeSpec (xs + q) r
> | otherwise = TimeSpec xs xn
@mightybyte
mightybyte / twitter.sch
Last active March 3, 2016 10:21
Small snippet illustrating the use of http://reply.obsidian.systems
(define-syntax elAttr
(syntax-rules ()
((elAttr tag attrs children ...)
(eval-element 'tag 'attrs 'children ...))))
(define-syntax el
(syntax-rules ()
((el tag children ...)
(elAttr tag () children ...))))
newtype AceRef = AceRef { unAceRef :: JSVal }
data ACE t = ACE
{ aceRef :: AceRef
, aceValue :: Dynamic t String
}
------------------------------------------------------------------------------
startACE :: String -> IO AceRef
#ifdef ghcjs_HOST_OS
data CurAppState = Login | Home | Other
app :: MonadWidget t m => CurAppState -> m ()
app Login = ...
app Home = ...
app Other = ...
navBar :: MonadWidget t m => m (Event t CurAppState)
navBar = do
a <- button "Login"
@mightybyte
mightybyte / DynListDemo.hs
Created June 14, 2016 05:05
DynamicList Demo
-- Paste this into http://hsnippet.com after adding Reflex.Dom.Contrib.Widgets.DynamicList
-- to the imports list in HSnippet's imports tab.
app :: MonadWidget t m => App t m ()
app = do
addItem <- button "Add Item"
dynamicList single snd (const never) ("edit me" <$ addItem)
["alpha", "bravo", "charlie"]
return ()
$ cabal sandbox add-source ../cabal/Cabal
$ cabal install
Warning: the --global flag is deprecated -- it is generally considered a bad
idea to install packages into the global store
Resolving dependencies...
Notice: installing into a sandbox located at
/Users/mightybyte/haskell/packunused-0.1.1.4/.cabal-sandbox
Configuring ansi-terminal-0.6.2.3...
Configuring old-locale-1.0.0.7...
Configuring split-0.2.3.1...
@mightybyte
mightybyte / download-pages.md
Last active August 30, 2016 15:30
Programming Language Download Pages
@mightybyte
mightybyte / FileLoader.hs
Created January 2, 2017 04:46
Reflex file loader
fileLoader :: MonadWidget t m => FileInputConfig t -> m (Event t Text)
fileLoader cfg = do
fls <- fmapMaybe listToMaybe . updated . value <$> fileInput cfg
reader <- liftIO newFileReader
performEvent_ $ ffor fls $ \f -> liftIO $
readAsDataURL reader (Just f)
wrapDomEvent reader (`on` load) $ do
res <- liftIO $ fromJSValUnchecked =<< getResult reader
let Right contents = decodeUtf8 <$> B64.decode
(encodeUtf8 $ snd $ T.breakOnEnd "base64," res)
{-# LANGUAGE DeriveFunctor #-}
module Form where
import Control.Lens
import Data.Default
import Data.Functor.Compose
import Data.Monoid
import Reflex
@mightybyte
mightybyte / gist:33fed8318386983cd1b6064edba67034
Created December 5, 2017 04:27
zsh completion debug file
+_complete_debug:20> : zsh 5.0.8
+_complete_debug:21> _main_complete
+_main_complete:11> local 'IFS=
'
+_main_complete:25> eval 'local -A _comp_caller_options;
_comp_caller_options=(${(kv)options[@]});
setopt localoptions localtraps localpatterns ${_comp_options[@]};
local IFS=$'\'' \t\r\n\0'\''
enable -p \| \~ \( \? \* \[ \< \^ \#
exec </dev/null;