Skip to content

Instantly share code, notes, and snippets.


Dan Allen mojavelinux

View GitHub Profile
mojavelinux / actual.png
Last active Dec 7, 2020
Flexbox alignment challenge: How do we get the green boxes to be flush with the right margin while keeping the wrap behavior the same?
mojavelinux / jruby-thread-safety-test.rb
Created Apr 7, 2020
JRuby thread safety test with Asciidoctor PDF and Rouge
View jruby-thread-safety-test.rb
require 'asciidoctor-pdf'
require 'java'
java_import 'java.util.concurrent.Callable'
java_import 'java.util.concurrent.FutureTask'
java_import 'java.util.concurrent.LinkedBlockingQueue'
java_import 'java.util.concurrent.ThreadPoolExecutor'
java_import 'java.util.concurrent.TimeUnit'
class App
include Callable
mojavelinux / file.rb
Last active Jan 23, 2020
View file.rb
class File
class << self
def absolute_path? path
(path.start_with? '/') || (ALT_SEPARATOR && (path.start_with? (absolute_path path).slice 0, 3))
end unless method_defined? :absolute_path?
mojavelinux /
Created Jan 19, 2020
Script to cut Asciidoctor EPUB3 release
# GEM_VERSION=1.5.0.alpha.10 ./ -p
while getopts "p" option; do
case $option in
p) PUSH=true ;;
mojavelinux / syntax-highlighter-rouge.rb
Last active Mar 22, 2019
Prototype of the Rouge syntax highighter integration for Asciidoctor. Now bundled with Asciidoctor. See
View syntax-highlighter-rouge.rb
class RougeSyntaxHighlighter < Asciidoctor::SyntaxHighlighter::Base
register_for 'rouge'
def initialize *args
@requires_stylesheet = nil
@style = nil
def highlight?
mojavelinux / syntax-highlighter-prism.rb
Last active Oct 19, 2020
Prototype of the Prism syntax highighter integration for Asciidoctor
View syntax-highlighter-prism.rb
class PrismSyntaxHighlighter < Asciidoctor::SyntaxHighlighter::Base
register_for 'prism'
def format node, lang, opts
opts[:transform] = proc do |pre, code|
if node.attr? 'linenums', nil, false
pre['class'] += ' line-numbers'
if (start = node.attr 'start', nil, false)
pre['data-start'] = start
mojavelinux / server-in-thread-multiple-clients.rb
Last active Jan 8, 2019
Running an HTTP server in a background thread in Ruby (for use in tests, for example)
View server-in-thread-multiple-clients.rb
# serve multiple clients at once
require 'socket'
require 'net/http'
server = 4040
server_thread = Thread.start do
loop do
Thread.start server.accept do |socket|
/^GET (\S+) HTTP\/1\.1$/ =~ socket.gets.chomp
path = $1
mojavelinux / nodegit-private-clone-test.js
Created May 21, 2018
Clone a private repository using nodegit
View nodegit-private-clone-test.js
const git = require('nodegit')
const fs = require('fs-extra')
const { URL } = require('url')
const REPO_URL = ''
const CLONE_DIR = '/tmp/private-repo-clone-test'
;(async () => {
await fs.emptyDir(CLONE_DIR)
let authAttempted = false
await git.Clone.clone(REPO_URL, CLONE_DIR, {
mojavelinux / asciidoctor-browser-include-spec.adoc
Last active Mar 15, 2018
Asciidoctor browser include spec: Specifies how Asciidoctor resolves the target of an include directive in the browser environment.
View asciidoctor-browser-include-spec.adoc

Include directive processing in the browser

This document describes how the include directive is processed in the browser environment (xmlhttprequest IO module). This handling has slightly different rules than when a file-based document. The rules are listed in the order in which they are applied.

In these definitions, there are several commonly occurring terms that pertain to the include directive:

  • target - the target of the include directive as specified in the document

  • include path - the resolved path of the include; usually an absolute path or URL

mojavelinux / echo-template-literal.js
Created Jan 2, 2018
A simple JavaScript template literal function that echos the string, populating all interpolated values.
View echo-template-literal.js
* Usage:
* const name = 'World'
* const place = '2018'
* console.log(echo`Hello, ${name}. Welcome to ${place}.`)
function echo (literals, ...values) {
return literals.length > 1
? values.reduce((accum, value, idx) => accum + value + literals[idx + 1], literals[0])
: literals[0]