Skip to content

Instantly share code, notes, and snippets.

View costa's full-sized avatar

Costa Shapiro costa

View GitHub Profile
@costa
costa / docker-volume-clone.sh
Created January 28, 2026 14:23
Clone a docker volume for fun and profit (stopping attached containers, if needed for data integrity, is on you)
#!/bin/bash -e
test "$#" -ne 2 && echo "USAGE ...docker-volume-clone <OLD> <NEW>" >&2 && exit 145
cd "$( dirname "${BASH_SOURCE[0]}" )"/..
docker volume create --name "$2"
docker run --rm -v "$1:/from" -v "$2:/to" eeacms/rsync rsync -a /from/ /to/
@costa
costa / gemini
Created January 19, 2026 14:01
gemini.google.com (a genAI) "gemini cli" docker (restricted) runner script -- to be run in a project root directory
#!/bin/bash -e
cwd="$( pwd )"
test -t 0 && tty_opt=t
docker run --rm -i$tty_opt -v "$cwd:$cwd" -w "$cwd" node npx @google/gemini-cli
@costa
costa / claude
Created January 19, 2026 13:59
Claude.AI (a genAI) "claude-code" docker (restricted) runner script -- to be run in a project root directory
#!/bin/bash -e
cwd="$( pwd )"
test -t 0 && tty_opt=t
docker run --rm -i$tty_opt -v "$cwd:$cwd" -w "$cwd" node npx -y @anthropic-ai/claude-code
@costa
costa / git-hub-submodulate
Last active December 23, 2025 18:16
Do not be afraid of submodules! Run this from the umbrella repo directory, give it the path to a subdirectory with a GitHub-checked-out (sub) repo in it.
#!/bin/bash
test "$#" -ne 1 && echo "USAGE ...git-hub-submodulate <PATH-TO-SUB-REPO-FROM-GITHUB>" >&2 && exit 145
git submodule add --name "$1" "$( git -C $1 config --get remote.origin.url )" "$1"
@costa
costa / expect_in_time_spec_helper.rb
Last active June 25, 2025 12:00
expect_in_time (a simple "macro" for your simple RSpec polling and timing-out needs)
# Polling expectation blocks with total timeouts
# NOTE the `expect`s go in the block, e.g. `expect_in_time(3) { expect(q.pop).to eq 'fin' }`
# NOTE beware of polling busy wait, insert `sleep`s in the block as needed
require 'timeout'
def expect_in_time(sec, &blk)
errors = []
begin
Timeout.timeout sec do
begin
@costa
costa / logging_handlers_httphandler_json.py
Last active February 21, 2025 17:22
Python (3.12+ish tested) logging.handlers.HTTPHandler JSON support monkey-patching
# NOTE Le monkey patch
# (https://github.com/python/cpython/blob/main/Lib/logging/handlers.py as of 2025-02-19)
def http_json_emit(self, record):
"""
Emit a record.
Send the record to the web server as a percent-encoded dictionary
"""
try:
@costa
costa / git_helper.rb
Last active September 21, 2024 10:49
Git-based "report-skip-retry" RSpec helper for detailing code version releases and more efficient testing -- just `require` it in your spec_helper.rb
# NOTE As seen at https://gist.github.com/costa/f9ae7184ca254b25f98872ae7a170358
#
# Keeps spec (https://RSpec.info) test results (as YAML) in Git commit messages
#
# NOTE Makes sense for heavy or lengthy (e.g. manual) tests, both for
# - documenting the results in the repo
# - splitting testing sessions
require 'yaml'
require 'git'
@costa
costa / manual_helper.rb
Last active October 23, 2024 07:46
Manual (e.g. human-terminal-based) RSpec helper -- just `require` it in your spec_helper.rb
# NOTE As seen at https://gist.github.com/costa/1f7a77d0949a1ee1f612fcd35b4fc23e
#
# Enables proper manual (human operator / QA) testing (with https://RSpec.info)
#
# NOTE It is recommended to tag manual specs with `, manual: true`,
# -- so they can be skipped with `$ rspec -t ~manual` when human is not present.
#
# DSL:
# - #explain "<MESSAGE-TO-OPERATOR>"
# - #demand "<OPERATOR-TO-CHECK>"
@costa
costa / integ_spec.rb
Created June 29, 2024 14:51
drv/icloud's formal specification (with RSpec, excerpt) -- a part of self server system
# ...definitions...
describe "REST API" do
# ...
context "when authenticated, with a sample video" do
# ...setup...
describe 'PUT /media/YYYY/MM/DD/IMG_NNNN.MOV' do
it "downloads media (a video) if it doesn't exist" do
expect(File.exist? video_path).not_to be
rest_put({}, "media/#{@media_path}")
expect_in_time 30 do # NOTE the file just started to download
@costa
costa / integ_spec.rb
Created June 29, 2024 14:23
vlog-youtuber's formal specification (with RSpec, excerpt)
# ...definitions...
describe "Automated publishing" do
# ...setup...
it "should happen whenever .pub.video is comitted to 'log' git repo" do
expect((channel_ids = api_get).length).to eq 1
expect(youtube_channel_url = api_get(channel_ids[0])[:pub_url].to_s).not_to be_empty
Dir.chdir LOG_PROJ_DIR do
sample_pub_video_path = File.join(TODAY_DATE_PATH, 'chang-wash-fun.pub.video')
sample_pub_ffmprb_path = File.join(TODAY_DATE_PATH, 'chang-wash-fun.pub.ffmprb')
sample_pub_video_text =