Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Allen mojavelinux

View GitHub Profile
@mojavelinux
mojavelinux / app.rb
Created Mar 4, 2022
Ruby program to print Hello, World!
View app.rb
puts 'Hello, World!'
@mojavelinux
mojavelinux / module-lookup-paths.js
Created Sep 17, 2021
Shows where Node.js is looking to find a module
View module-lookup-paths.js
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')
View graceful-vfs-src-with-gs-and-pipeline.js
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 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
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
mojavelinux / file.rb
Last active Jan 23, 2020
File.absolute_path?
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?
end
end
@mojavelinux
mojavelinux / cut-release.sh
Created Jan 19, 2020
Script to cut Asciidoctor EPUB3 release
View cut-release.sh
#!/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 Mar 22, 2019
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
View 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 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
end