Stylized Alex Ward logo

Blog

Site Now in Metalsmith + Let's Encrypt

Metalsmith Rework

I recently got the bug to try something new and run my site using a static site generator instead of Drupal.

There are several reasons:

  1. I wasn't really using any of the features of Drupal, and having a static site committed somewhere made more sense.
  2. I've been writing more and more JS things, and since PHP is my day job I thought it'd be nice to have something else.
  3. Metalsmith had been brought up before, as had Hexo and a couple of others (there are a few php ones as well, along with Jekyll for ruby).
  4. The computer I was working on had npm installed but not php (it was windows, and I didn't want to type choco install php)

I ultimately went with metalsmith because it looked cool, and the idea of its render pipeline. There are also a bunch of plugins and the plugin api is pretty easy to understand once you've got it figured out.

Couple of problems I ran into:

  1. The render pipeline takes a bit of trial and error in order to get right.
  2. Plugin documentation doesn't always include examples.
  3. Sometimes the generator creates some weirdness with regards to the template plugin (header repeated, double titles, etc.).

Let's Encrypt

I've also switched the SSL certificate to use a beta cert from Let's Encrypt. It was fairly easy to get going (there's an automated installer to generate and pull down the cert) and it seems to be working just fine. It's a pretty cool initiative which I hope eventually gets everything behind SSL.

Why you should write in Markdown

What's all this then?

I had a bit of free time this afternoon, and decided I should take a moment to talk about one of my favorite things: Markdown. In the post, I'd like to talk about what I've been using Markdown for and a few of the services and tools I've been looking at and using. Hopefully it'll be useful!

Markdown is awesome

Let's get this disclaimer out of the way up front. I <3 Markdown. I use it to write basically everything (this post brought to you by the Markdown Module ). It's not for everyone, and for publishing it's not going to replace Publisher or Pages anytime soon, especially for things with highly complex layouts.

In my case, Markdown fits my needs very well.

Writing is awesome

Since we've established that Markdown is awesome (for me), it follows that getting to write things in Markdown is also essential. Even more so when you can do things like write standard reports, books, and anything else that could potentially be published in Markdown.

Thus, recently I've been working with Gitbook - a publishing platform and node package which can convert structured Markdown files into a book, which is styled according to the default gitbook css. At Acquia, my team has also been doing a fair amount of work with using GitBook's open source node module to write reports in.

I have to say that GitBook is a pleasure to work with. I find myself spending less time having to deal with formatting quirks, and more time proofreading and writing the things I want to produce.

Why GitBook is nice

With GitBook, the way it wants you to structure your book makes it pretty intuitive to keep the file structure well aligned with the structure of your outline.

At minimum, you need a README.md and a summary.md. The summary file contains the outline of your book, chapters, subchapters, etc. This can then be used to automatically generate folders for your book to go into using the gitbook init command. Double fun, because it's smart enough to not overwrite files that already exist, so you can use it to stub out files for you while you're working.

The README serves as the summary file for the book, and appears at the front as an introduction. Both of these files are configurable by editing the book.json file and pointing them to different locations.

Want a cover? No problem. By default simply placing a cover.jpg file in that directory will produce a book cover. You can also change what this file is with config values in book.json.

Once you've written a bunch and want to convert your book into a pdf or epub file, gitbook has you covered there too (though you do need calibre installed to do it properly).

All in all, it makes my life easier since it takes away the pain of having to deal with a full-fledged Word Processor which may or may not generate things in a consistent manner.

GitBook Editor

For my workflow, I use Atom to write the book and then make use of the gitbook serve command in order to preview changes to my book as I'm writing. It's a workflow that works really well for me.

However, GitBook also provides a really slick editor that hooks nicely into their gitbook.com service (the publishing platform). It does the same kinds of things that I do in Atom, but also provides a WYSIWYG editor side pane (which Atom can also do), and a lot of nice features for speeding up editing if you don't want to just type the Markdown.

Publishing to Gitbook.com

I've not done this yet, but the whole process seems pretty reasonable. If you choose to charge for your book, you receive 80% royalties. There's also a mechanism for taking donations, however I'm not 100% sure how that works.

And now for something completely different

I'm happy to also be acquainted with the creator of Remarq, a Markdown-based report generation tool. It generates beautiful PDF reports from your Markdown content and then templates it for you based upon some configuration settings which you can generate. Basically it allows you to create super-slick looking reports without having to futz with trying to make them look pretty.

Great if you're very focused on the content of a report and want to still create something visually appealing to the report's intended audience.

I don't personally use this for anything at the moment, but it's awesome and helps push my "Markdown for everything" agenda.

In Closing

Just give Markdown a shot, there are tons of editors you can play with and get previews on, and the syntax is super easy to use. Commonmark provides a basic spec and introduction, and Github has a nice Markdown Basics page which should help a lot.

MARKDOWN EVERYTHING.

Techlahoma Chat Bot take 2

So it has been a while since I first talked about creating amandaharlin_v2, and I figured it was time for an update.I originally spun up _v2 on Digital Ocean (which is what is hosting this blog), and everything worked out pretty well.

However, this left some things to be desired, as I was the only one in control of the server, and since I wasn't using any kind of node process manager. If irc would disconnect for extended periods of time, or the node process would die for any reason, I'd have to manually go restart the bot. Additionally, there wasn't an easy way to give access to the administrators of #techlahoma.

This is why I receently moved amandaharlin_v2 over to Heroku. The instructions for this are actually very well documented, and the process is not all that difficult.

The very first thing that you need to do is create the heroku app, which can be done with the heroku command line:

cd techlahoma-bot
heroku create

This automatically adds the heroku git repo url to the git repository within which the command was run.

After that, it's just a matter of using heroku:set to create the appropriate environment variables:

heroku config:set HUBOT_IRC_NICK=&quot;amandaharlin_v2&quot;
heroku config:set HUBOT_IRC_ROOMS=&quot;#techlahoma&quot;
heroku config:set HUBOT_IRC_SERVER=&quot;irc.freenode.net&quot;
heroku config:set HEROKU_URL=http://amandaharlin_v2.herokuapp.com/

That last one is used to ensure the application pings itself at the appropriate interval to ensure that it doesn't timeout when inactive.

Finally, the only last thing you need to do when pushing the bot is to update the Procfile in order to actually start the app:

web: bin/hubot -a irc -n amandaharlin_v2

After that, we're done! Huzzah.

The added bonus here is that I can also grant access to the various #techlahoma leadership to adminster the app directly instead of having to create ssh accounts for them.

Techlahoma Chat Bot

Today while I was talking in #techlahoma, the topic of chatbots came up. Being something of a chat bot connoisseur, I (with @amandaharlin's blessing) have set out to tell you how to get your very own hubot up and running on IRC.

First, let's talk briefly about my chat bot history. I've written a Python chat bot from scratch to connect with an XMPP server. His name was kittenbot, and he was awesome. As a result, I got very familiar with XMPP's XEP-0045, which is the specification for multi user chat. Fortunately, the good folks over at @github have given us a lot more to work with than I did in the Kittenbot days.

Awesome. So let's get cracking.

First thing you should do is go grab an ice-cold beer. I've gone with Prarie Wine Barrel Noir. It's particularly delicious and well suited to making hubots.

The second thing you need to do is install the latest version of node. I've built it from source on ubuntu, which is an amazingly simple process. Instructions can be found over at Joyent.

You need then to get the required npm packages for hubot:

npm install -g hubot coffee-script

After you have that installed, you'll need to create your new hubot. This is done simply with:

hubot --create techlahoma-bot

This will create a new techlahoma-bot directory in whatever root directory you specified. I'll be putting this code up athttps://github.com/cthos/techlahoma-bot.
Next step is to install the new hubot's brain! This runs on redis by default, which is fine. I'm not going to be super picky and just install the redis-server package provided by my host. Once that's installed, it is running on the proper port by default, so that's all we need to do.

After that, we need to make some minor modifications to the Package.json file. For some reason, the one generated by hubot --create does not include the correct version for hubot-scripts. We need to change the line:

'hubot-scripts': '>= 3.5.0 < 3.0.0',

To

'hubot-scripts': '2.5.14',

Great! Now hubot is able to actually run. Now we need to pick and choose some awesome things from the Hubot Script Catalog to have our bot be capable of by editing hubot-scripts.json:

[
'redis-brain.coffee',
'shipit.coffee',
'abstract.coffee',
'ackbar.coffee',
'alot.coffee',
'beeradvocate.coffee',
'karma.coffee',
'tell.coffee'
]

We are close now! The only thing left to do is set 3 environment variables, and install the irc adapter!

npm install hubot-irc --save
export HUBOT_IRC_NICK='amandaharlin_v2'
export HUBOT_IRC_ROOMS='#techlahoma'
export HUBOT_IRC_SERVER='irc.freenode.net'

Cool! Everything is good to go, just need to fire it up with:

bin/hubot -n amandaharlin_v2 --adapter irc

WE NOW HAVE BOT. ALL GLORY TO amandaharlin_v2!

Postscript:
I did most of this work from a Microsoft Surface. It's a really solid tablet, and I'm actually pretty impressed by it.

ircd-ratbox and ratbox-services in Ubuntu

I recently decided to get an IRC server up and running to see how complicated it would be compared to installing ejabberd.

After looking through some of the packages available on Ubuntu through the standard repositories. I wanted to have Nickserv and Chanserv running, so I was hoping to get something with services included. Originally, I tried ircd2, but I didn't find a decent services package which worked with it. So then I was going to try dancer-ircd, because it had a dancer-services package. Turns out dancer-services was removed from the package repos due to a bug that was never corrected.

Thus, after a bit of poking I decided to go with ircd-ratbox and ratbox-services.

Installing Ratbox

Ratbox is pretty easy to install, and it has a very large (and very snarky) sample configuration file for you to work off of. It recommends that you read the entire thing first before starting to configure your real ircd.conf file. It then forces the point because there's a configuration variable which will shut down the server if you haven't been reading the entire thing (I'll give you a hint. It's called "havent_read_conf", and it's in the general block). Okay, fine. After a lot of head banging and some finagling I manage to get ircd-ratbox functional. That is all well and good, but unfortunately getting ratbox-services functional was a different story.

Wrestling with ratbox-services

First thing you need to do is get a back end for ratbox-services to run off of. I originally went with the sqlite backend, but there was a problem I was unable to resolve where it was unable to write to the db file. So then I switched to mysql. The problem there was the mysql db isn't installed by anything, so I had to go hunting for the mysql configuration file. It was not in an intuitive place (/usr/share/ratbox-services/lib/schema-mysql.sql).

The other undocumented problem was that NickServ is disabled by default (why? Why was that turned off?).

All in all it was not super difficult to get running after a careful reading of the configuration files, there were some gotchas which took me quite a long time to get figured out.

Views Link Issue with Replacements

So, I was working on getting a particular view which rattles off a list of categories working to link off to another view that has a Contextual Filter on said category field to list off all matching content items with said value in the field. Similar to Taxonomy terms, but being linked from a select dropdown. I was using the output as link option, with a replacement filter to put the value of the item into the url. Everything was pretty straightforward, except for one little snag. One of my categories had a forward slash in it. Now, normally I would think this / would be url encoded to %2F, but that wasn't happening.

I did some digging, by utilizing hook_views_pre_render to modify what it was sending to the display, and I found that it was in fact running through drupal_encode_path. Here's the full text of that method:

return str_replace('%2F', '/', rawurlencode($path));

As you can see, that's just urlencoding the string you're sending to it, and then decoding the slash. That means that no matter what I do in hook_views_pre_render, I am totally unable to get that / encoded properly for the url. Bummer.

Eventually I hacked it by making a separate view for the offending item (there was ony one), but for now it looks like my best option is to not allow slashes in that particular drop-down.