Single-file version control. Lighter than RCS.
cp rev.rb /usr/local/bin/rev
Requires Ruby, diff and patch. Colored output when git is available.
| require "fiddle" | |
| require_relative "settable_superclass" | |
| class Klass | |
| using SettableSuperclass | |
| HEAP_TYPE = ->(obj) { Fiddle::Pointer.new(Fiddle.dlwrap(obj))[0, Fiddle::SIZEOF_VOIDP].unpack1("J") & 0x1f } | |
| private_constant :HEAP_TYPE |
| [2, 3, 1].sort_by { Reverse[it] } | |
| #=> 3, 2, 1 |
| require 'optparse' | |
| module Kernel | |
| def OptionParser(&) | |
| fields = OptionParser.new(&).top.list.filter_map do |option| | |
| if option.is_a?(OptionParser::Switch) | |
| name = option.long&.first || option.short&.first | |
| name.delete_prefix('-').delete_prefix('-').to_sym | |
| end | |
| end |
| class Alert < Module | |
| COLORS = {red: 31, yellow: 33, blue: 34, magenta: 35, cyan: 36} | |
| def initialize(message: nil, color: :red) | |
| super() | |
| @message = message | |
| @color = COLORS.fetch(color) | |
| end | |
| def included(base) |
| module Example | |
| ONCE = Once.new | |
| def self.once | |
| ONCE.call do | |
| # work | |
| end | |
| end | |
| end |
| defmodule FizzBuzz.Native do | |
| @moduledoc false | |
| use Rustler, otp_app: :fizz_buzz | |
| def classify(_nums), do: :erlang.nif_error(:nif_not_loaded) | |
| end |
| Words = Data.define(:argv, :stdin) | |
| class Words | |
| STDIN_ARGV = ["-"].freeze | |
| include Enumerable | |
| def initialize(argv: ARGV, stdin: $stdin) = super | |
| def each(&) | |
| return enum_for(__method__) unless block_given? |
| #!/usr/bin/env -S falcon-host | |
| # frozen_string_literal: true | |
| require "falcon/environment/rack" | |
| require "roda" | |
| class App < Roda | |
| route do |r| | |
| r.root { "wombat" } | |
| end |
| require 'optparse' | |
| class Options < Ruby::Box | |
| class Into | |
| class BadKeyError < ArgumentError | |
| def initialize(key) = super("Bad key: #{key.inspect}") | |
| end | |
| def []=(key, value) | |
| global = "$#{key.to_s.delete_prefix('$').tr('-', '_')}" |