summaryrefslogtreecommitdiff
path: root/posts
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-08-03 17:43:40 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-08-03 17:43:40 +0200
commit52b67951f1e8a7f1af9b85d4ae8e7689d194574a (patch)
tree88076113c7020e8483e5f47afa618d6449034f7e /posts
parent230688a0b842cf57b316a7ba62910ca387afbce7 (diff)
downloaddirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.gz
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.bz2
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.tar.xz
dirty-haskell.org-52b67951f1e8a7f1af9b85d4ae8e7689d194574a.zip
Working prototype in hakyll
Diffstat (limited to 'posts')
-rw-r--r--posts/blog-documentation.md5
-rw-r--r--posts/blog-rss.md39
-rw-r--r--posts/pwutil.md119
3 files changed, 0 insertions, 163 deletions
diff --git a/posts/blog-documentation.md b/posts/blog-documentation.md
deleted file mode 100644
index 7db843d..0000000
--- a/posts/blog-documentation.md
+++ /dev/null
@@ -1,5 +0,0 @@
1% On the Origin of dirty-haskell.org
2
3The software used is a trivially modified version of the one powering [math.kleen.org](http://math.kleen.org/lists/blog.html).
4
5The title is without deeper meaning. \ No newline at end of file
diff --git a/posts/blog-rss.md b/posts/blog-rss.md
deleted file mode 100644
index 4e8cb24..0000000
--- a/posts/blog-rss.md
+++ /dev/null
@@ -1,39 +0,0 @@
1% dirty-haskell.org´s rss feeds
2
3I extended the software suite inherited from [math.kleen.org](http://math.kleen.org) to include support for rss feeds.
4The heart of the issue is a ~80 line haskell script I chose to call, in a bout of creativity, "generate-rss.hs".
5The script uses the [feed](http://hackage.haskell.org/package/feed-0.3.9.2) package.
6
7generate-rss.hs gets passed a title and a list of paths below ./lists to incorporate as items.
8It generates an empty feed structure, adds title and a (hardcoded) base url for RSS metadata, and iterates over the given paths — generating for each path an item to be included in the finished feed.
9This procedure makes use of a state monad (StateT (Feed, Maybe ClockTime) IO ()) to sequentially add items to the feed and keep track of the modification/change time of the newest path examined.
10Each item carries a title, an url, a date, and contents as follows:
11
12- The date used is the modification/change time of the path supplied as a command line argument at the beginning of the program (usually a symbolic link in ./lists) — as such it is the time the post was linked into the particular list we´re generating a RSS feed for (this was not a deliberate design choice but a side effect of the canonical implementation — it was later decided that this behaviour was in fact the one expected all along).
13- The url is generated by following, recursively, the trail of symbolic links starting in ./lists, assuming the final target is indeed in ./posts, and forming the filename of that target into a (hopefully) functional url in a hardcoded fashion.
14- The title is extracted from the markdown file using a function shamelessly copied from extract-title.hs (The author wrote that one too, after all).
15- The contents are read into Pandoc and rendered into [AsciiDoc](http://en.wikipedia.org/wiki/AsciiDoc) format (it seemed convenient at the time).
16
17Along the way two helper functions were introduced — if an implementation of those already exists in Prelude or somewhere else common please mail in a comment:
18
19~~~ {.haskell}
20(<->) :: [(a -> b)] -> a -> [b]
21[] <-> _ = []
22(f:fs) <-> x = (f x:fs <-> x)
23
24(<-->) :: [(a -> a)] -> a -> a
25[] <--> x = x
26(f:fs) <--> x = fs <--> (f x)
27~~~
28
29## Update ##
30
31~~~ {.haskell}
32import Control.Applicative ((<*>), pure)
33
34(<->) fs = (<*>) fs . pure
35
36(<-->) = flip $ foldl (.) id
37~~~
38
39Thanks, viktor.
diff --git a/posts/pwutil.md b/posts/pwutil.md
deleted file mode 100644
index 176ffdc..0000000
--- a/posts/pwutil.md
+++ /dev/null
@@ -1,119 +0,0 @@
1% A Tool to Manage a Set of YAML Objects Representing Account Information — pwutil
2
3A long time ago I wrote a bunch of scripts (first in bash, then zsh, and later perl) to manage a, sometimes encrypted, file containing account information I get asked to create and remember on a daily basis—accounts for shopping websites spring to mind.
4
5[pwutil](git://git.yggdrasil.li/pwutil) is the newest iteration in this line of bunches of scripts.
6
7## Features
8
9 * Support for embedding common operation in any kind of record keeping
10
11 Thus support for almost any encryption known to man (with absolutely no online security), version control, and synchronisation
12 * [Human read- and writeable](https://en.wikipedia.org/wiki/YAML) backstore
13 * Machine parseable output
14 * [Command Line Interface](https://en.wikipedia.org/wiki/Command-line_interface)-only
15 * New accounts can be partially generated by user defined functions with out of the box support for [pwgen](http://sourceforge.net/projects/pwgen/) and SSH
16
17## Usage
18
19~~~
20pwget [<searchTerm> …]
21Looks up and returns all accounts which contain any <searchTerm> anywhere in their representation — case insensitive.
22
23pwadd [[--gen-<generator> [<generatorArgument> …] …] --] <identifier> [<attributeKey> <attributeValue> …]
24Adds an account to the store — does not overwrite.
25~~~
26
27## Documentation
28
29I shall document the project in a partial and file-wise fashion—amendments available on request.
30
31### Structure
32
33~~~ {#DirTree}
34pwutil
35├── default.nix
36├── PWAdd.hs
37├── PWGet.hs
38├── PWUtil
39│   ├── Extra
40│   │   ├── PWGen.hs
41│   │   └── SSHCmd.hs
42│   ├── Types.hs
43│   └── Util.hs
44├── pwutil.hs
45├── PWUtil.hs
46└── pwutil.nix
47~~~
48
49### `pwutil.nix`
50is a [nix](https://nixos.org/nix) expression allowing easy installation using the nix package manager.
51A `~/.nixpkgs/config.nix` allowing one to do so might look thus:
52
53~~~ {.numberLines}
54{
55 packageOverrides = pkgs: {
56 pwutil = pkgs.callPackage /path/to/pwutil.nix {};
57 };
58}
59~~~
60
61The derivation takes some arguments (write those in `{}` above):
62
63`main ? null`
64 ~ Overwrite `pwutil.hs` with a file path
65
66`with<Package> ? false`
67 ~ `<Package>` is one of Pwgen, or Ssh a the current time.
68 If `true` wraps executables to have `$PATH` include `<Package>`.
69
70### `Types.hs`
71
72Introducing `PW` (much as [xmonad](https://xmonad.org) did with `X`) is an easy way to keep track of the `PWConfig` without resorting to function arguments.
73`BackStore` is our (new and improved) way of encapsulating store access in a totally customisable way—`plain`, which is essential `readFile` and `writeFile` as provided by `ByteString`, is provided for convenience in `Util.hs`.
74`PWConfig` most importantly contains a definition of generators (called by passing `--gen-…` to `pwadd`).
75
76~~~ {#Types.hs .haskell .numberLines}
77module PWUtil.Types (
78 PW(..),
79 BackStore(..),
80 PWConfig(..),
81 Generator(..)
82 ) where
83
84import Control.Monad.State
85import qualified Data.Map as M
86import Data.Yaml
87import Data.ByteString
88
89type PW = StateT PWConfig IO
90
91data BackStore = BackStore
92 { readContents :: PW ByteString
93 , writeContents :: ByteString -> PW ()
94 }
95
96data PWConfig = PWConfig
97 { generators :: M.Map String Generator
98 , backstore :: BackStore
99 }
100
101type Generator = [String] -> PW Value
102~~~
103
104
105### `pwutil.hs`
106
107is, in a [xmonad](http://xmonad.org) kind of way, the configuration file—the shipped default is reproduced below as a template for custom configs.
108
109~~~ {#pwutil.hs .haskell .numberLines}
110import PWUtil
111
112import System.FilePath ((</>))
113import System.Directory (getHomeDirectory)
114
115main :: IO ()
116main = do
117 h <- getHomeDirectory
118 runPW (emptyConfig { backstore = plain (h </> "accounts.yaml") }) pwutil
119~~~