Posts tagged with code

Org-mode formatting improvements

2018-03-13 posts code emacs

org-mode is so much better with some rich formatting. It really makes it appealing as a text format with embedded and actionable code — whether that is as a source file for literate-programming or just some notes with code snippets.

I've added the following to my .emacs, based on Org as a Word Processor:

;; org-mode formatting improvements

(require 'org-bullets)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
(add-hook 'org-mode-hook (lambda () (whitespace-mode -1)))

(setq org-hide-emphasis-markers t)

(let* ((variable-tuple (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
                             ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
                             ((x-list-fonts "Verdana")         '(:font "Verdana"))
                             ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
                             (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro."))))
       (base-font-color     (face-foreground 'default nil 'default))
       (headline           `(:inherit default :weight bold :foreground ,base-font-color)))

  (custom-theme-set-faces 'user
                          `(org-level-8 ((t (,@headline ,@variable-tuple))))
                          `(org-level-7 ((t (,@headline ,@variable-tuple))))
                          `(org-level-6 ((t (,@headline ,@variable-tuple))))
                          `(org-level-5 ((t (,@headline ,@variable-tuple))))
                          `(org-level-4 ((t (,@headline ,@variable-tuple :height 1.1))))
                          `(org-level-3 ((t (,@headline ,@variable-tuple :height 1.25))))
                          `(org-level-2 ((t (,@headline ,@variable-tuple :height 1.5))))
                          `(org-level-1 ((t (,@headline ,@variable-tuple :height 1.75))))
                          `(org-document-title ((t (,@headline ,@variable-tuple :height 1.5 :underline nil))))))

And then I start the .org files with the following parameters:

#+STARTUP: indent
#+STARTUP: odd
#+STARTUP: hidestars
#+STARTUP: showall
#+TITLE: document title
Makefile to pre-process downloaded podcasts

2017-08-26 bookmarks code

I recently updated my podcast pre-processing script to Python 3.6 & the multiprocessing.Pool module and then a few days later realized the whole thing would be much better as a simple Makefile

The goal is to:

  1. reduce filesize of podcasts (192kbit/s is overkill for spoken word!)
  2. normalize the volume and convert to mono (easier to listen to when riding/running and it's windy)
  3. speed up playback (people talk too slow!)
  4. strip tags (so my dinky mp3 player doesn't put the podcasts into different "folders")
  5. Source:


Getting new posts from friends on Facebook with Selenium

2017-08-16 posts python code

I made a little script that uses Selenium to create a single page containing all the new posts from my Facebook friends.

This lets me see everything that is posted without having to seek it out and wade through the ads and other things Facebook is trying to recommend to me.

The output is currently very rough, but it'll do for now - in particular, it just screenshots the post, rather than trying to extract the content and re-render it.

Python, Go and Rust bot comparison

2017-06-01 posts code

After implementing my bot in Python, I thought I'd try porting it to other languages as an opportunity to learn a bit of Go and Rust.

Both Go and Rust are statically typed and compile to a single self-contained binary, which is appealing as there is no need to maintain a virtualenv and install dependencies on the server.

The parsing code for "rain" messages is a good starting point to compare the bots. Each is using a "parser combinator" library to parse the messages.

Quick thoughts: Python & Go are both pretty sane. There's almost certainly a better way in Rust, but I found it considerably harder.

The tests are stored in different places in each version so the total line count is not comparable, and the Rust version includes "ignore case" code that is built into Python's parser combinators, and that I added into a fork of the Go parser library.