Skip to content

Instantly share code, notes, and snippets.

View mojavelinux's full-sized avatar

Dan Allen mojavelinux

View GitHub Profile
mojavelinux / app.rb
Created March 4, 2022 11:40
Ruby program to print Hello, World!
puts 'Hello, World!'
mojavelinux / module-lookup-paths.js
Created September 17, 2021 06:37
Shows where Node.js is looking to find a module
const Module = require('module')
Module._resolveLookupPaths = new Proxy(Module._resolveLookupPaths, {
apply(target, self, args) {
return target.apply(self, args)
const fs = require('fs')
const gs = require('glob-stream')
const File = require('vinyl')
const { Transform } = require('stream')
const map = (transform) => new Transform({ objectMode: true, transform })
const ospath = require('path')
//const isUTF8 = require('is-utf8')
const { pipeline } = require('stream')
function smartStat (path_, callback) {
mojavelinux / actual.png
Last active December 7, 2020 10:41
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 April 7, 2020 10:34
JRuby thread safety test with Asciidoctor PDF and Rouge
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 January 23, 2020 08:36
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 January 19, 2020 00:04
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 March 22, 2019 21:32
Prototype of the Rouge syntax highighter integration for Asciidoctor. Now bundled with Asciidoctor. See
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 October 19, 2020 02:41
Prototype of the Prism syntax highighter integration for Asciidoctor
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 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 = 4040
server_thread = Thread.start do
loop do
Thread.start server.accept do |socket|
/^GET (\S+) HTTP\/1\.1$/ =~ socket.gets.chomp
path = $1