Skip to content

Instantly share code, notes, and snippets.

View glv's full-sized avatar

Glenn Vanderburg glv

View GitHub Profile
glv / vpackage.p
Created October 31, 2019 16:23
TeX's vpackage subroutine
function vpackage(p: pointer; h: scaled; m: small_number; l: scaled): pointer;
label common_ending, exit;
var r: pointer; {the box node that will be returned}
w, d, x: scaled; {width, depth, and natural height}
s: scaled; {shift amount}
g: pointer; {points to a glue specification}
o: glue_ord; {order of infinity}
last_badness := 0;
r := get_node(box_node_size); {function}
glv / .rubocop.yml
Last active August 25, 2019 16:49
Rubocop configuration (draft)
# This is not a valid .rubocop.yml file. See gist comment for explanation.
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
# Ruby is an expression language. Continued lines should be aligned with the
# expression they're part of, not the beginning of the line they happened to
# start on.
glv / choose_preferred_name.rb
Last active September 22, 2018 16:47
Using Ruby's "case" without a matching object
def preferred_over?(other_name)
when partial_name? && !other_name.partial_name?
when other_name.partial_name? && !partial_name?
max_preference >= other_name.max_preference
glv /
Last active July 22, 2024 09:39
Ruby and PostgreSQL Regular Expressions

Ruby and Postgres Regular Expression Syntaxes

Ruby's regular expressions are unusually powerful. Postgres' regular expressions are not as powerful, but they come close; close enough that it's possible to do many pattern-based queries and string transformations entirely in a query.

And sometimes, it's very useful to have a single regular expression that works

glv /
Last active January 5, 2023 21:45
Automatically prepend "bundle exec" when appropriate (in fish shell).
# This sets up fish so that, if you type a command that should be
# run using Bundler, it first automatically prepends "bundle exec"
# to the command line buffer before executing it. Works for all
# commands found in the "bin" directory of the current bundle.
# To override this behavior and run such a command without Bundler,
# prefix with "command" (e.g., `command rake -T`)
# Pros (vs binstubs or aliases):
# * automatically adjusts to bundle changes
glv / percentages.rb
Created July 1, 2016 19:32
Dave Thomas' Ruby puzzler
# What is the value of this Ruby expression?
% % % % %
# There's a trailing space, which is important!
# It evaluates to "%". Why? It's equivalent to this:
%|%|% %|%|
# which parses as:
glv / blockchain_proof.txt
Created February 26, 2016 16:41
Blockchain identification
Verifying that +glennv is my blockchain ID.
glv /
Last active January 19, 2024 19:41
Comparing monadic and non-monadic styles for managing state in Clojure

The Clojure State Monad: A Non-Trivial Example

When I started writing this in early 2013, I intended it to be a series of blog posts about effective use of the state monad (and the `algo.monads` library in general) in Clojure. Along the way, I learned that `algo.monads` is both somewhat buggy and extremely slow, and I decided that the most effective way to use monads in Clojure was simply not to use them at all. Therefore, I abandoned work on the post. But it's still probably useful as a good way of explaining the state monad by example, so I've spruced the old draft up slightly and am posting it here.


There are too many monad tutorials, and not enough practical examples of solving real problems with monads. This article shows how to use

glv /
Last active November 3, 2019 14:00
@tenderlove asked about the wisdom of teaching RSpec to new Ruby developers. I have some relevant experience. Here it is, for what it's worth.

Notes on teaching both test/unit and RSpec to new Ruby developers

@tenderlove asked "Is it good to teach RSpec (vs t/u) to people who are totally new to Ruby?" I have experience suggesting that it is a good thing; after a short back and forth, it seemed useful to write it up in detail.


This goes back several years, to when I was the primary Ruby/Rails trainer for Relevance from 2006-2009. I'm guessing that worked out to probably 6-8 classes a year during those years. Since then, RSpec has changed a fair amount (with the addition of expect) and test/unit has changed radically (it has an entirely new implementation, minitest, that avoids some of the inconsistencies that made test/unit a bit confusing during the time I'm writing about here).

I started out as an RSpec skeptic. I've never been afraid of what a lot of people denigrate as "magic" in Ruby libraries … to me, if you take the trouble to understand it, that stuff's just pr

Keybase proof

I hereby claim:

  • I am glv on github.
  • I am glv ( on keybase.
  • I have a public key whose fingerprint is 0CF3 D473 4F46 7494 1975 290C DA1F 2F76 9F2F 5496

To claim this, I am signing this object: