Skip to content

Instantly share code, notes, and snippets.

from dataclasses import dataclass
from typing import Literal, Protocol, Optional
class Side:
...
class Wombat:
...
#!/usr/bin/env ruby
require "json"
require "net/http"
require "uri"
require "irb"
sentry_auth_token = ENV.fetch("SENTRY_AUTH_TOKEN")
# https://codingdojo.org/kata/Args/
require "minitest"
class TestArgs < Minitest::Test
def test_args
parser = ArgsParser.new(l: :bool, p: :int, d: :str)
args = parser.parse(*%w[-l -p 8080 -d /usr/logs])
https://github.com/qmacro/level-up-your-json-fu-with-jq/blob/main/talknotes.md
pbpaste | from json
pbpaste | save environment.json
# jq '.availableEnvironments|length' environments.json
open environment.json | get availableEnvironments | length
# jq -r '.[].name' offerings.json
server.modules = (
...
"mod_webdav",
...
)
$HTTP["host"] =~ "weave.foo.com" {
server.document-root = "/foo/weave"
accesslog.filename = "/var/log/lighttpd/weave/access.log"
webdav.activate = "enable"
array5<array5<int5>> X;
X.each(function (row) {
row.each(function (cell) {
invariant cell.between?(1, 5);
});
});
function valid?(ary) {
invariant ary.uniq?;
# frozen_string_literal: true
source "https://rubygems.org"
gem "jasmine", git: "https://github.com/jasmine/jasmine-gem.git", branch: "main"
extension Int {
var bcd: [UInt8] {
var d: [UInt8] = []
var n = self
while n > 0 {
let (q, r) = n.quotientAndRemainder(dividingBy: 100)
let (hundreds, tens) = r.quotientAndRemainder(dividingBy: 10)
d.append(UInt8((hundreds << 4) | tens))
n = q
}
#!/usr/bin/env ruby -w
require "openssl"
FLD_DIGIT_SHIFT = 6;
FLD_DIGIT_MASK = (0b111 << FLD_DIGIT_SHIFT);
FLD_NUMSECONDS_SHIFT = 0;
FLD_NUMSECONDS_MASK = (0b11 << FLD_NUMSECONDS_SHIFT);
def bcd(str)