diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-08-03 17:43:40 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-08-03 17:43:40 +0200 |
commit | 52b67951f1e8a7f1af9b85d4ae8e7689d194574a (patch) | |
tree | 88076113c7020e8483e5f47afa618d6449034f7e /posts | |
parent | 230688a0b842cf57b316a7ba62910ca387afbce7 (diff) | |
download | dirty-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.md | 5 | ||||
-rw-r--r-- | posts/blog-rss.md | 39 | ||||
-rw-r--r-- | posts/pwutil.md | 119 |
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 | |||
3 | The software used is a trivially modified version of the one powering [math.kleen.org](http://math.kleen.org/lists/blog.html). | ||
4 | |||
5 | The 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 | |||
3 | I extended the software suite inherited from [math.kleen.org](http://math.kleen.org) to include support for rss feeds. | ||
4 | The heart of the issue is a ~80 line haskell script I chose to call, in a bout of creativity, "generate-rss.hs". | ||
5 | The script uses the [feed](http://hackage.haskell.org/package/feed-0.3.9.2) package. | ||
6 | |||
7 | generate-rss.hs gets passed a title and a list of paths below ./lists to incorporate as items. | ||
8 | It 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. | ||
9 | This 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. | ||
10 | Each 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 | |||
17 | Along 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} | ||
32 | import Control.Applicative ((<*>), pure) | ||
33 | |||
34 | (<->) fs = (<*>) fs . pure | ||
35 | |||
36 | (<-->) = flip $ foldl (.) id | ||
37 | ~~~ | ||
38 | |||
39 | Thanks, 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 | |||
3 | A 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 | ~~~ | ||
20 | pwget [<searchTerm> …] | ||
21 | Looks up and returns all accounts which contain any <searchTerm> anywhere in their representation — case insensitive. | ||
22 | |||
23 | pwadd [[--gen-<generator> [<generatorArgument> …] …] --] <identifier> [<attributeKey> <attributeValue> …] | ||
24 | Adds an account to the store — does not overwrite. | ||
25 | ~~~ | ||
26 | |||
27 | ## Documentation | ||
28 | |||
29 | I shall document the project in a partial and file-wise fashion—amendments available on request. | ||
30 | |||
31 | ### Structure | ||
32 | |||
33 | ~~~ {#DirTree} | ||
34 | pwutil | ||
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` | ||
50 | is a [nix](https://nixos.org/nix) expression allowing easy installation using the nix package manager. | ||
51 | A `~/.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 | |||
61 | The 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 | |||
72 | Introducing `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} | ||
77 | module PWUtil.Types ( | ||
78 | PW(..), | ||
79 | BackStore(..), | ||
80 | PWConfig(..), | ||
81 | Generator(..) | ||
82 | ) where | ||
83 | |||
84 | import Control.Monad.State | ||
85 | import qualified Data.Map as M | ||
86 | import Data.Yaml | ||
87 | import Data.ByteString | ||
88 | |||
89 | type PW = StateT PWConfig IO | ||
90 | |||
91 | data BackStore = BackStore | ||
92 | { readContents :: PW ByteString | ||
93 | , writeContents :: ByteString -> PW () | ||
94 | } | ||
95 | |||
96 | data PWConfig = PWConfig | ||
97 | { generators :: M.Map String Generator | ||
98 | , backstore :: BackStore | ||
99 | } | ||
100 | |||
101 | type Generator = [String] -> PW Value | ||
102 | ~~~ | ||
103 | |||
104 | |||
105 | ### `pwutil.hs` | ||
106 | |||
107 | is, 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} | ||
110 | import PWUtil | ||
111 | |||
112 | import System.FilePath ((</>)) | ||
113 | import System.Directory (getHomeDirectory) | ||
114 | |||
115 | main :: IO () | ||
116 | main = do | ||
117 | h <- getHomeDirectory | ||
118 | runPW (emptyConfig { backstore = plain (h </> "accounts.yaml") }) pwutil | ||
119 | ~~~ | ||