Skip to content

Instantly share code, notes, and snippets.

View mojavelinux's full-sized avatar

Dan Allen mojavelinux

View GitHub Profile
@mojavelinux
mojavelinux / multipage-html5-converter.rb
Created November 3, 2014 06:02
Multipage HTML5 converter for Asciidoctor
require 'asciidoctor'
class MultipageHtml5Converter
include Asciidoctor::Converter
include Asciidoctor::Writer
register_for 'multipage_html5'
EOL = "\n"
def initialize backend, opts
@mojavelinux
mojavelinux / syntax-highlighter-rouge.rb
Last active March 22, 2019 21:32
Prototype of the Rouge syntax highighter integration for Asciidoctor. Now bundled with Asciidoctor. See https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/syntax_highlighter/rouge.rb
class RougeSyntaxHighlighter < Asciidoctor::SyntaxHighlighter::Base
register_for 'rouge'
def initialize *args
super
@requires_stylesheet = nil
@style = nil
end
def highlight?
@mojavelinux
mojavelinux / server-in-thread-multiple-clients.rb
Last active January 8, 2019 23:02
Running an HTTP server in a background thread in Ruby (for use in tests, for example)
# serve multiple clients at once
require 'socket'
require 'net/http'
server = TCPServer.new 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
mojavelinux / asciidoctor-browser-include-spec.adoc
Last active March 15, 2018 07:41
Asciidoctor browser include spec: Specifies how Asciidoctor resolves the target of an include directive in the browser environment.

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
mojavelinux / test-asciidoctor.rb
Last active January 15, 2018 17:42
A Ruby script to load and render an AsciiDoc file using AsciiDoctor.
##!/usr/bin/env ruby
quiet = false
print = false
header_footer = true
while ARGV[0].to_s.start_with?('-')
case ARGV[0]
when '-o'
print = true
ARGV.shift
@mojavelinux
mojavelinux / echo-template-literal.js
Created January 2, 2018 03:27
A simple JavaScript template literal function that echos the string, populating all interpolated values.
/**
* 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]
@mojavelinux
mojavelinux / HeadlessMain.java
Created July 21, 2015 07:25
A main class wrapper for deck2pdf that runs the application headless using Monocle from jfxtras.org
package me.champeau.deck2pdf;
import java.lang.reflect.Field;
import java.util.Objects;
import javafx.application.Application;
/**
* Adapted from https://gist.github.com/hastebrot/cbca1128dd791966e3a6
*/
public class HeadlessMain {
@mojavelinux
mojavelinux / twitter.css
Last active June 17, 2017 20:23
User style to make Twitter square (and less bold) again; domain: twitter.com (for use with https://chrome.google.com/webstore/detail/stylist/pabfempgigicdjjlccdgnbmeggkbjdhd)
/*.content-main {
width: 600px;
}
.dashboard {
width: 285px;
}
.DashboardProfileCard-bg {
height: 94px;
@mojavelinux
mojavelinux / gitlab-readable.css
Last active May 12, 2017 00:45
Readable user style for GitLab Issues; match: ^https://gitlab\.com/.*/issues/.*$
.md, .wiki {
font-family: "Droid Serif";
font-size: 1.2em;
line-height: 1.6;
}
ul.notes .note .note-body .note-text p, .wiki p {
margin-top: 0.75em;
}
@mojavelinux
mojavelinux / apache-tomee-datanucleus.adoc
Last active April 28, 2017 15:12
Instructions for how to switch to DataNucleus as the JPA provider when testing with or deploying to Apache TomEE.

Using DataNucleus as the JPA provider in Apache TomEE

DataNucleus can be used as an alternate JPA provider in TomEE. This document describes how to make this switch. These instructions assume you are using container-managed JPA.