Skip to content

Instantly share code, notes, and snippets.

View mojavelinux's full-sized avatar

Dan Allen mojavelinux

View GitHub Profile
@mojavelinux
mojavelinux / app.rb
Created March 4, 2022 11:40
Ruby program to print Hello, World!
puts 'Hello, World!'
@mojavelinux
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) {
console.dir(args[1].paths)
return target.apply(self, args)
}
})
require('name-of-module')
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
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?
actual.png
@mojavelinux
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
mojavelinux / file.rb
Last active January 23, 2020 08:36
File.absolute_path?
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?
end
end
@mojavelinux
mojavelinux / cut-release.sh
Created January 19, 2020 00:04
Script to cut Asciidoctor EPUB3 release
#!/usr/bin/bash
# GEM_VERSION=1.5.0.alpha.10 NEXT_GEM_VERSION=1.5.0.alpha.11.dev ./cut-release.sh -p
PUSH=false
while getopts "p" option; do
case $option in
p) PUSH=true ;;
esac
done
@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 / 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
end
@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