Standard escape codes are prefixed with Escape:
- Ctrl-Key:
^[ - Octal:
\033 - Unicode:
\u001b - Hexadecimal:
\x1B - Decimal:
27
| require 'bundler/inline' | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem 'colorize' | |
| end | |
| class MatcherInterface | |
| def initialize(some_object) | |
| @some_object = some_object |
| # Minimal example of getting a PostgREST API running from scratch for | |
| # testing purposes. It uses docker to launch a postgres database and | |
| # a postgrest api server. | |
| # This should not be used to deploy a production system but to | |
| # understand how postgrest works. In particular there is no security | |
| # implemented, see the docs for more. | |
| # https://postgrest.org/en/v4.4/ |
| import Darwin | |
| @dynamicMemberLookup | |
| struct Environment { | |
| subscript(dynamicMember name: String) -> String? { | |
| get { | |
| guard let value = getenv(name) else { return nil } | |
| return String(validatingUTF8: value) | |
| } |
| # Given a long-running process in the terminal: | |
| # | |
| # - Ctrl+Z to suspend it | |
| # - Run `keep-track` | |
| # - Output resumes, when done will show a notification with the time it took for the process to run | |
| # | |
| # Can be customized with an `--icon` to `notify-send`, | |
| # maybe a sound effect added in the `&&` list. | |
| # | |
| function keep-track() { |
| # spec/support/shared_context/rake.rb:1 | |
| # from: https://robots.thoughtbot.com/test-rake-tasks-like-a-boss | |
| # version updated to deal with task like `rails one:two:three | |
| # also I hide `invoke` in shared_context | |
| # frozen_string_literal: true | |
| require 'rake' | |
| shared_context 'rake' do |
| module IncrementAndDecrement | |
| def increment(&block) | |
| matcher = change(&block).by(1) | |
| RSpec::Matchers::AliasedMatcher.new(matcher, lambda do |desc| | |
| desc.gsub("changed", "incremented").gsub("change", "increment") | |
| end) | |
| end | |
| def decrement(&block) | |
| matcher = change(&block).by(-1) |
| #include <stdlib.h> | |
| /* | |
| * Defer an expression. | |
| * This requires a block in an outer scope to have called defer_init, | |
| * and the deferred statements will run once defer_run is called. | |
| */ | |
| #define defer(expr) \ | |
| do { \ | |
| __label__ _defer_label; \ |