Skip to content

Instantly share code, notes, and snippets.

@cabo
cabo / crlf.screenrc
Created December 19, 2015 13:33
Make GNU screen convert return key (CR) into CR-LF
# put this in your ~/.screenrc to make
# ^A D (uppercase) switch on, and
# ^A U (uppercase) switch off, converting
# CR (return keys) input into CRLF
bind D bindkey "\015" stuff "\015\012"
bind U bindkey "\015" stuff "\015"
@cabo
cabo / rfc7405.rb
Created July 2, 2023 08:53
ABNF: Convert RFC 7405 case-sensitive strings to RFC 5234
s = ARGF.read
s.gsub!(/%s"([^"]+)"/) {
"%x#{$1.chars.map{|c|c.ord.to_s(16)}.join(".")}"
}
puts s
@cabo
cabo / gist:605385
Created September 30, 2010 21:50
Making Emacs German-friendly
(set-language-info-alist
"German8" '((tutorial . "TUTORIAL.de")
(charset unicode)
(coding-system utf-8 iso-latin-1 iso-latin-9)
(coding-priority utf-8 iso-latin-1)
(nonascii-translation . iso-8859-1)
(input-method . "german-postfix")
(unibyte-display . iso-latin-1)
(sample-text . "\
German (Deutsch Nord) Guten Tag
@cabo
cabo / jsondiff.rb
Created March 10, 2023 09:46
Diff two JSON files after normalizing them with jq
#!/usr/bin/env ruby
require 'open3'
require 'tempfile'
require 'shellwords'
if ARGV.size != 2
warn "** usage: jsondiff.rb j1 j2"
exit 63
end
files = ARGV.dup.map do |arg|
#!/usr/bin/env ruby
require 'rexml/document'
require 'open3'
default_fn = "svg-fig-00"
d = REXML::Document.new(ARGF)
REXML::XPath.each(d.root, "//svg:svg", {"svg" => "http://www.w3.org/2000/svg"}) do |x|
fn = default_fn.succ!
@cabo
cabo / tag-report.rb
Created September 12, 2021 22:13
What is the state of consumption of the various ranges available for allocating CBOR tags?
#!/usr/bin/env ruby -Ku
# coding: utf-8
require 'rexml/document'
require 'open-uri'
# require 'open-uri/cached'
CBOR_TAGS = "https://www.iana.org/assignments/cbor-tags/cbor-tags.xml"
ACCEPT_XML = {"Accept" => "application/xml"}
@cabo
cabo / minutes-wurst.rb
Created September 5, 2021 15:50
Get recent minutes for an IETF WG as a big Wurst. Useful for mining and searching. Mining PDF not yet implemented.
#!/usr/bin/env ruby -Ku
Encoding.default_external = "UTF-8" # wake up, smell the coffee
require 'kramdown'
# FIX THIS dirname:
# You need to be in the root of the proceedings directory as obtained via rsync,
# e.g. in my case via: rsync -av rsync.ietf.org::proceedings ~/std/proceedings
# Warning: ~ 50 GB!
def remove_indentation(s)
l = s.lines
indent = l.grep(/\S/).map {|l| l[/^\s*/].size}.min
l.map {|l| l.sub(/^ {0,#{indent}}/, "")}.join
end
class Array
def uniq_c
each_with_object(Hash.new(0)) { _2[_1] += 1 }
end
end
#!/usr/bin/env ruby -Ku -i.bak
fail "Usage: section1.rb foo.md" unless ARGV.size == 1
s = ARGF.read
SECTIONS_RE = /Section(?:s? (?:[\w.]+, )*[\w.]+,? and)? [\w.]+/
puts s.gsub(/(#{SECTIONS_RE}\s+of)\s+{{([-\w.]+}})/) { "{{#$1 #$2" }
# Note that we don't fix "Section 3 and 5 of {{foo}}" into "Sections 3 and 5 of {{foo}"
# -- that must be done manually, with all the not so easy to recognize section references