Skip to content

Instantly share code, notes, and snippets.

@et4te
et4te / OCanvas.hs
Created October 7, 2015 20:13
Use of oCanvas in Reflex
{-# LANGUAGE JavaScriptFFI #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Scorch.OCanvas
(
mkCanvas
, canvasDisplay
, canvasAddChild
@et4te
et4te / OCanvas.hs
Created October 7, 2015 18:19
Line 24 is where I am confused
mkCanvas' :: CanvasInfo -> IO (OCanvasRef)
mkCanvas' cnvInfo = do
cnvObj <- toJSRef cnvInfo
cnvRef <- js_create cnvObj
js_setWidth cnvRef (toJSInt $ width cnvInfo)
js_setHeight cnvRef (toJSInt $ height cnvInfo)
return cnvRef
mkCanvas :: (MonadWidget t m) => Event t CanvasInfo -> m (Event t OCanvasRef)
@et4te
et4te / ListItem.hs
Created October 6, 2015 16:57
Gives 'non-exhaustive pattern' in Basic at Console
listItemAttrDyn False =
"class" =: "list-item"
listItemAttrDyn True =
"class" =: "list-item highlight"
listItem :: (MonadWidget t m) => (String -> String) -> m (ListItem t)
listItem mkUrl = do
rec highlightDyn <- foldDyn (\a _ -> a) False highlightE
itemAttributesDyn <- mapDyn listItemAttrDyn highlightDyn
@et4te
et4te / Fugly.hs
Created October 2, 2015 00:29
Fugly but working
{-# LANGUAGE JavaScriptFFI #-}
module Scorch.GHCJS.File
(
readFileAsync
) where
import Control.Monad.Trans (liftIO)
import GHCJS.Types
import GHCJS.Foreign
import GHCJS.DOM.File (File)
@et4te
et4te / sample.hs
Created August 24, 2015 20:17
Trying to filter the events
processEvent :: NE.NonEmpty ViewEvent -> EventState -> EventState
processEvent trigger (_, ij, nm) =
case NE.head trigger of
Init ->
(Just Refresh, ij, nm)
Prev ->
prevEvent ij nm
Next ->
nextEvent ij nm
@et4te
et4te / deriv.lisp
Created August 29, 2011 15:24
Regex Derivatives
;; base types
(defvar *regex-null* nil)
(defvar *regex-empty* t)
;; predicates
(defun regex-alt? (re)
(and (consp re) (eq (car re) 'alt)))
(defun regex-seq? (re)
(and (consp re) (eq (car re) 'seq)))
(defun regex-rep? (re)
@et4te
et4te / latest-ver.lisp
Created August 27, 2011 23:24
latest version
;; Examples
;;------------------------------------------------------------------------------
;; 1. non-commands
;; There are two types of 'non-commands',
;; a) integers
;; b) symbols
;;
;; Symbols are looked up, so if you provide an initial environment, with a
;; symbol defined, it will be appropriately looked up.
;; e.g: (lookup 'x '((x . 0))) -> 0
@et4te
et4te / fwd2.lisp
Created August 27, 2011 20:24
The compiler frontend
;; Examples
;;------------------------------------------------------------------------------
;; 1. non-commands
;; There are two types of 'non-commands',
;; a) integers
;; b) symbols
;;
;; Symbols are looked up, so if you provide an initial environment, with a
;; symbol defined, it will be appropriately looked up.
;; e.g: (lookup 'x '((x . 0))) -> 0
(defparameter *white-colour* #\O)
(defun make-image (m n)
(make-array (list m n) :initial-element *white-colour*))
(defun clear (image)
(loop for i from 0 below (reduce #'* (array-dimensions image)) do
(setf (row-major-aref image i) *white-colour*)))
@et4te
et4te / luhn-will.lisp
Created August 18, 2011 21:38
solution-less-naive
;;------------------------------------------------------------------------------
(eval-when (:compile-toplevel)
(ql:quickload :series))
(defpackage luhn
(:use :cl :series))
(in-package :luhn)
;;-- sums integer digits as long as x is < 100.