28th June, 2011
FOlder – straightforward forms
So I’ve got a problem. Every year I have to gather together a set of paper based forms and put them in a folder to hand to someone for QA processing. Most of these forms start off in some word-processing package, but by the time that they require review by a colleague and multiple signatures they end up on paper – it’s simply easier. But I’m not too good with paper and I’m even worse with uncodified processes that I follow once a year. Surely there’s a way to codify a process of handling documents? Yeah, there are plenty of tools that do it. And here’s another…
FOlder gives you a web based methods of creating, and writing documents. It’s based on the amazing Aoha-Editor and the fantastic Happstack. So the technical plumbing is thoroughbred, using a (soon-to-be) distributed (guaranteed) ACID data store. It’s missing three major features
- Authentication (coming in version 0.1),
- Collating the created files in a folder (simple fix in version 0.2),
- Digital signatures (straightforward to implement, hard to devise a good UI).
and one minor feature
- upload PDFs which are viewable using PDF.js.
You can find the source code here. I’m happy to accept patches!
Posted at 10:22 pm | Comments Off
28th June, 2011
FOlder – straightforward forms
So I’ve got a problem. Every year I have to gather together a set of paper based forms and put them in a folder to hand to someone for QA processing. Most of these forms start off in some word-processing package, but by the time that they require review by a colleague and multiple signatures they end up on paper – it’s simply easier. But I’m not too good with paper and I’m even worse with uncodified processes that I follow once a year. Surely there’s a way to codify a process of handling documents? Yeah, there are plenty of tools that do it. And here’s another…
FOlder gives you a web based methods of creating, and writing documents. It’s based on the amazing Aoha-Editor and the fantastic Happstack. So the technical plumbing is thoroughbred, using a (soon-to-be) distributed (guaranteed) ACID data store. It’s missing three major features
- Authentication (coming in version 0.1),
- Collating the created files in a folder (simple fix in version 0.2),
- Digital signatures (straightforward to implement, hard to devise a good UI).
and one minor feature
- upload PDFs which are viewable using PDF.js.
You can find the source code here. I’m happy to accept patches!
Update:
A quick hacked video on YouTube (uploaded in WebM so it shouldn’t require flash)
Posted at 10:22 pm | Comments Off
28th June, 2011
FOlder – straightforward forms
So I’ve got a problem. Every year I have to gather together a set of paper based forms and put them in a folder to hand to someone for QA processing. Most of these forms start off in some word-processing package, but by the time that they require review by a colleague and multiple signatures they end up on paper – it’s simply easier. But I’m not too good with paper and I’m even worse with uncodified processes that I follow once a year. Surely there’s a way to codify a process of handling documents? Yeah, there are plenty of tools that do it. And here’s another…
FOlder gives you a web based methods of creating, and writing documents. It’s based on the amazing Aoha-Editor and the fantastic Happstack. So the technical plumbing is thoroughbred, using a (soon-to-be) distributed (guaranteed) ACID data store. It’s missing three major features
- Authentication (coming in version 0.1),
- Collating the created files in a folder (simple fix in version 0.2),
- Digital signatures (straightforward to implement, hard to devise a good UI).
and one minor feature
- upload PDFs which are viewable using PDF.js.
You can find the source code here. I’m happy to accept patches!
Update:
A quick hacked video on YouTube (uploaded in WebM so it shouldn’t require flash)
Posted at 10:22 pm | Comments Off
28th June, 2011
FOlder – straightforward forms
So I’ve got a problem. Every year I have to gather together a set of paper based forms and put them in a folder to hand to someone for QA processing. Most of these forms start off in some word-processing package, but by the time that they require review by a colleague and multiple signatures they end up on paper – it’s simply easier. But I’m not too good with paper and I’m even worse with uncodified processes that I follow once a year. Surely there’s a way to codify a process of handling documents? Yeah, there are plenty of tools that do it. And here’s another…
FOlder gives you a web based methods of creating, and writing documents. It’s based on the amazing Aloha-Editor and the fantastic Happstack. So the technical plumbing is thoroughbred, using a (soon-to-be) distributed (guaranteed) ACID data store. It’s missing three major features
- Authentication (coming in version 0.1),
- Collating the created files in a folder (simple fix in version 0.2),
- Digital signatures (straightforward to implement, hard to devise a good UI).
and one minor feature
- upload PDFs which are viewable using PDF.js.
You can find the source code here. I’m happy to accept patches!
Update:
A quick hacked video on YouTube (uploaded in WebM so it shouldn’t require flash)
Posted at 10:22 pm | Comments Off
28th June, 2011
FOlder – straightforward forms
So I’ve got a problem. Every year I have to gather together a set of paper based forms and put them in a folder to hand to someone for QA processing. Most of these forms start off in some word-processing package, but by the time that they require review by a colleague and multiple signatures they end up on paper – it’s simply easier. But I’m not too good with paper and I’m even worse with uncodified processes that I follow once a year. Surely there’s a way to codify a process of handling documents? Yeah, there are plenty of tools that do it. And here’s another…
FOlder gives you a web based methods of creating, and writing documents. It’s based on the amazing Aloha-Editor and the fantastic Happstack. So the technical plumbing is thoroughbred, using a (soon-to-be) distributed (guaranteed) ACID data store. It’s missing three major features
- Authentication (coming in version 0.1),
- Collating the created files in a folder (simple fix in version 0.2),
- Digital signatures (straightforward to implement, hard to devise a good UI).
and one minor feature
- upload PDFs which are viewable using PDF.js.
You can find the source code here. I’m happy to accept patches!
Update:
A quick hacked video on YouTube (uploaded in WebM so it shouldn’t require flash)
Posted at 10:22 pm | Comments Off
4th June, 2011
Three Haskell web frameworks
This model-view-controller pattern has been kicking around for quite some time now. It’s a nice way of separating concerns in many applications including web apps. And, a modern web-framework should both let you separate concerns and, ideally, bridge the gap between your programming model and data storage model. Some really nice people have done this in Ruby and Python and Python and …. well you get the picture. If you like a programming language there are probably several modern web-frameworks for it. So can we ask that question about Haskell? How would a modern web-framework work in a language that allows easy parallelisation, straightforward concurrency and even software transactional memory. Here’s my brief take on three Haskell web frameworks, with the caveat that I’ve only used one in anger (unsurprisingly my favourite one).
Snap Framework has been getting a lot of press lately. It’s fast. Faster than node.js but if you look at the documentation it appears that it uses a similar model to node.js i.e. a fast event loop. Snap provides a templating language called Heist. It has a nice method of handling RESTful queries (code stolen from here)
site :: Application ()
site = route [ ("/", index)
, ("/echo/:stuff", echo)
]
serveDirectory "resources/static"
Which just fires things off to specific handlers. Nice. And, just for good measure, I’ve stolen this heist snippet too
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Home Page</h1>
<apply template="nav"/>
<p>Welcome to our home page</p>
</body>
</html>
Snap leaves the choice of a storage backend up to the developer. They’ve got good reasons for this, however if doesn’t endear me. I’m happer with smart people doing all the integration work and giving me something to use.
Yesod gives you the choice of using either sqlite or postgres as a backing store. And it’ll do automagic migration of database schemas. Defining a datatype for storage is simple
mkPersist [$persist|
Entry
title String
day Day Desc
content Html'
deriving
|]
Again, this code is stolen from the very excellent tutorial. But this is looking straightforward, I get a Haskell datatype that’s persisted to a standard, trustworthy relational data store. Now, the people who are writing Snap seem to be scary smart and like to make fast things even faster, but this guy who develops Yesod seems to want to give me all the tools I need to just make a web app. It’s worth looking at his screencasts to see how easy OpenID and Facebook authentication is in a Yesod app. Furthermore, Yesod provides Hamlet, Cassius and Julius – respectively HTML, CSS and JavaScript templating languages. Julius, in particular, seems to have been designed with jQuery in mind. This, again, makes sense to me. Someone is giving me great tools to produce web apps under the standard use-case i.e. nice RESTful blingy things. You can even see that the Yesod query routing is simple
mkYesod "Blog" [$parseRoutes|
/ RootR GET
/entry/#EntryId EntryR GET
/admin AdminR EntryCrud defaultCrud
|]
And finally we get to Happstack. Happstack is the most mature of the three and features a wonderful data store called MACID. MACID has acid super powers but it distributes. I get to store any Haskell structure I want in a secure, distributed data-store! Representing reasonably complex information is easy
$(deriveAll [''Show, ''Eq, ''Ord, ''Default]
[d|
-- |ConferenceSubmission: a paper submitted to the conference
data ConferenceSubmission = ConferenceSubmission
{ author :: String
, title :: String
, date :: ClockTime
, email :: String
}
-- |Conference: a list of ConferenceSubmission
newtype Conference = Conference { conferenceSubmissions :: [ConferenceSubmission] }
|])
Routing is a little hairy, but you get a lot of power from it. And it’s nicely monadic.
appHandler =
do decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096) -- decode the request body if present.
msum [ methodM GET >> renderIndex -- matches /
, renderSubmissions =<< conferenceHandler
]
conferenceHandler :: ServerPartT IO (HSP XML)
conferenceHandler =
dir "submissions" $ msum [postSubmission, getEntries] -- RESTful /submissions
Happstack uses Blaze or HSP or many other options for its templating language. Again, Blaze and HSP both play well with jQuery.
I have a fun project to play with over the next few months. I think Happstack is what I’ll be using.
Posted at 9:52 pm | Comments Off
29th May, 2011
Graphviz and the functional graph library
A friend of mine asked how to display a Haskell Functional Graph Library (FGL) graph using graphviz. Turns out it’s really straightforward. Martin Erwig (the author of FGL) considered this when writing the library
$ ghci > let g=Data.Graph.Inductive.Example.dag4
Use one of the example graphs so that we can print it out. Then
> import Data.Graph.Inductive.Graphviz > graphviz g "Foo" (100.0, 100.0) (100, 100) Portrait
where the documentation for the graphviz function is here
Of course, you can do much more complex stuff with the graphviz package…but that’s for another day.
Posted at 9:20 pm | Comments Off
17th May, 2011
Creating Arbitrary Foo for QuickCheck
I always write semi-automated tests, whatever language I’m using. In Haskell my preferred framework is QuickCheck, which goes beyond what an XUnit framework is capable of. I come to QuickCheck as a convert from the old religion of Object Oriented programming. However much I’ve adopted functional practices I find myself, in the darkest of times, falling back on idioms from a past life. Recently I’ve been testing code that looks like the following:
data Squad = Squad { players :: Set Char,
team :: Set Char }
So what I’ve got is some type which is composed of a set and some other set which is a subset of the original. I hope the Squad metaphor is reasonable. In many sports you’ll have a panel of players, called the squad, and then for any given game you’ll have a team which is a subset of the players in your squad. To simplify this problem, each player is identified by a single character rather than a name. Now, we don’t have a dependent type system here. Just plain old Haskell. So the constraint that “team is a subset of players” is not enforced by the type system.
Now I want to tell Haskell to create Arbitrary instances of Squad.
randSubset :: Ord a => Set a -> Gen (Set a)
randSubset xs = do {
mask <- vectorOf (Set.size xs) arbitrary;
return (Set.fromList [ e | (e,True) <- zip (Set.toList xs) mask ]) }
instance Arbitrary Squad where
arbitrary = do {
players <- listOf1 (arbitrary :: Gen Char);
team <- randSubset (Set.fromList players);
return (Squad (Set.fromList players) team))}
The smarts here is in randSubset, but listOf1 ensures that there’s at least one player in our squad. I was struggling when playing around with a random number generator, to try and pull out random elements from a Set. Such thinking is a false idol. With some guidance from the only person on the planet to be 90% Real Jedi I realised you can just use the common generator combinators as provided by QuickCheck.
So the fragment
do {
mask <- vectorOf (Set.size xs) arbitrary;
return (Set.fromList [ e | (e,True) <- zip (Set.toList xs) mask ])}
asks for an arbitrary list of boolean values where the list is the same length as the size of the input Set. Then where the ith element of the list is true, the ith element of the set is considered to be in the subset, or omitted otherwise. It’s a nice idiom, useful anywhere you’re playing with sets that aren’t quite arbitrary themselves, but are constrained to be a subset of another.
Posted at 3:48 pm | Comments Off
