Skip to content

Instantly share code, notes, and snippets.

View dbaynard's full-sized avatar

David Baynard dbaynard

  • Fore Stun Ltd
View GitHub Profile
@dbaynard
dbaynard / gist:8807189
Last active August 29, 2015 13:56
Convert an RTF from ApE to LaTeX using vim

RTF (ApE) -> LaTeX

Eventually, this will become a script. Until then…

Mostly automated

First, find all strings of bases (except the last)

/\v([0-9]*1) .{-} ([0-9]*0)/e
@dbaynard
dbaynard / Fix-encoding.md
Last active July 18, 2016 23:50
Fix latin1 encoding issues (mysql in particular) using vim

Fix encoding issues (e.g. ’ ~ ’)

WARNING: You must copy the commands from the raw version of this document. The markdown converter doesn’t like it…

Do you have a file with weird encoding errors? Perhaps instead of you have á^€™. The cause is a mix up between latin1 (usually — and especially if mysql is involved — the windows cp1252 encoding) and utf8.

Many solutions drop bytes. This has the advantage that you can see every change that is made, as it happens, should you wish.

It requires the file to be encoded in ISO 8859–1.

@dbaynard
dbaynard / Takeover-website.md
Last active August 14, 2016 22:51
Incremental API takeover

Ever been faced with an old website that needs an upgrade best done incrementally? At http://www.parsonsmatt.org/2016/06/24/take_over_an_api_with_servant.html, Matt Parsons describes an approach to incrementally take over an old API using Servant and a reverse proxy, which is worth a read!

On occasions, though, your predecessor may not have written a considered, documented API. Sometimes all that exists is a sprawl of tangled php, html and javascript that just about works, until there’s a change in business logic and the code gets touched — at which point everything breaks. Unlike the example in Matt’s post, it has an index.php route with all the pages at index.php?page=<PAGE>, instead of using path pieces separated by solidus.

Matt’s approach works in this case too, and we don’t even need to change the haskell server he supplies! We simply change how we use the reverse proxy and add some url rewriting middleware.

This example copies Matt’s woofing and meowing server, for simplicity of comparison.

---
title: passhte
author: David Baynard
date: 22 May 2017
fontfamily: libertine
csl: chemical-engineering-science.csl
link-citations: true
abstract: |
Paste over ssh
...
@dbaynard
dbaynard / humble.md
Created May 31, 2018 10:59
Downloading purchases (pdf books) from humble bundle

Super hacky, original method

Requires

  • jq
  • pandoc
  • Browser with dev tools (much easier than navigating source)
  • aria2c for batch downloading
  • text editor with f&r
  1. Go to purchase page.
@dbaynard
dbaynard / Forestay.lhs
Created November 25, 2018 14:36
Haskell snippets
---
title: Forestay
author: David Baynard
date: 05 Jun 2017
fontfamily: libertine
csl: chemical-engineering-science.csl
link-citations: true
abstract: |
...
@dbaynard
dbaynard / diagonal-span.hs
Last active December 17, 2018 22:19
A correct-by-construction AST representation of typographic tables, using diagonalization
-- |
-- Module : diagonal-span
-- Copyright : David Baynard 2018
-- License : BSD-3-Clause OR Apache-2.0
--
-- Maintainer : haskell@baynard.me
-- Stability : experimental
-- Portability : unknown
--
-- A proposal for a correct by construction abstract syntax tree for pandoc
@dbaynard
dbaynard / jindosh.lhs
Created January 17, 2019 11:23
Jindosh
---
title: Jindosh puzzle
author: David Baynard
date: 16 Jan 2019
fontfamily: libertine
csl: chemical-engineering-science.csl
link-citations: true
abstract: |
...
@dbaynard
dbaynard / git-review.sh
Created February 11, 2019 16:19
Pull github PRs for review
#!/usr/bin/env zsh
#
# Review github PRs.
#
# This script makes reviewing github PRs simple. Supply the requester's branch
# in the form it is presented at the top of the PR on github (i.e. user:branch).
# This adds:
#
# - a new remote corresponding to the user, with only the PR branch
# - a new local branch (unless a branch with that name exists already, in
resolver: lts-13.5
name: 8.6.3-13.5-baynard-snapshot
compiler: ghc-8.6.3
packages:
- git: https://github.com/jameysharp/corrode
commit: 34053342c2f1ca04f23ad94d67057f14e74d9fb9
- git: https://github.com/mgattozzi/curryrs
commit: 6d3ecbc3d1786ccc16e2ff20c6d6da53734f6b03