Skip to content

Instantly share code, notes, and snippets.

@camallen
camallen / edit-s3-remote-file.sh
Created February 20, 2025 06:29
Edit S3 remote file and upload
#!/usr/bin/env bash
SUM=$(which sha512sum || which sha || which md5sum || which md5 || true)
# modify the following to match the s3 setup you desire
path="s3://bucket_name/path/$1"
tempfile=$(mktemp ~/.tmpXXXXXX)
trap "rm -f $tempfile" INT TERM HUP EXIT
You are an expert in Ruby on Rails, Sorbet, PostgreSQL, Hotwire (Turbo and Stimulus) and Tailwind CSS.
Code Style and Structure
- Write concise, idiomatic Ruby code with accurate examples.
- Follow Rails conventions and best practices.
- Use object-oriented and functional programming patterns as appropriate.
- Prefer iteration and modularization over code duplication.
- Use descriptive variable and method names (e.g., user_signed_in?, calculate_total).
- Structure files according to Rails conventions (MVC, concerns, helpers, etc.).
@camallen
camallen / docker_run_cmd_as_root_user.sh
Last active August 9, 2024 04:45
How to run a cmd in docker as a different or root user
# docker
docker exec -it -u0 containerid bash
# compose
docker compose run --rm -u0 serviceid bash
@camallen
camallen / ebmp_known_bird_taxa.json
Last active July 29, 2022 09:34
Allowed birds in ebmp system
[
{ "common_name": "blue tit", "genus": "cyanistes", "species": "caeruleus", "bto_species_code": "bluti" },
{ "common_name": "great tit", "genus": "parus", "species": "major", "bto_species_code": "greti" },
{ "common_name": "coal tit", "genus": "periparus", "species": "ater", "bto_species_code": "coati" },
{ "common_name": "marsh tit", "genus": "poecile", "species": "palustris", "bto_species_code": "marti" },
{ "common_name": "nuthatch", "genus": "sitta", "species": "europaeus", "bto_species_code": "nutha" },
{ "common_name": "great spotted woodpecker", "genus": "dendrocopos", "species": "major", "bto_species_code": "grswo" },
{ "common_name": "goldcrest", "genus": "regulus", "species": "regulus", "bto_species_code": "goldc" },
{ "common_name": "goldfinch", "genus": "carduelis", "species": "carduelis", "bto_species_code": "goldf" },
{ "common_name": "blackbird", "genus": "turdus", "species": "merula", "bto_species_code": "blabi" },
@camallen
camallen / Dockerfile
Last active May 25, 2021 16:50
rails app multi stage docker builds
# Start from a small, trusted base image with the version pinned down
FROM ruby:2.5-slim-stretch AS base
# Install system dependencies required both at runtime and build time
# The image uses Postgres but you can swap it with mariadb-dev (for MySQL) or sqlite-dev
RUN apt-get update && \
apt-get install --no-install-recommends -y \
build-essential \
# git is required for installing gems from git repos
git \
@camallen
camallen / sidekiq_jobs_cleanup.rb
Created January 29, 2021 13:55
cleanup failed and retryable sidekiq jobs
# NOTE: sidekiq 6+ introduces new `.scan` method on Sets, use this when the version matches
# https://github.com/mperham/sidekiq/wiki/API#scan
# e.g. rs = Sidekiq::RetrySet.new, rs.scan('string-to-look-for')
# -----------------------------------------------------------------------
# remove any old jobs that won't finish and are in the DEAD set / Morgue
rs = Sidekiq::RetrySet.new
jobs_to_remove_from_retry = rs.select do |job|
# 'workflow_attached_image'
@camallen
camallen / search_index_update_subject_mime_types_gz_storage.py
Last active October 10, 2020 13:44
Update blob content types - use a search index to generate a list of az storage cli cmds
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient
from urllib.parse import urlparse
from progress.bar import Bar
from sys import platform
import re
import subprocess
import mimetypes
import sys
import os
@camallen
camallen / unretire_workflow_subjects.rb
Created September 25, 2020 13:07
Unretire subects for a workflow
workflow_ids = []
subject_set_ids = []
workflow_ids.map do |wf_id|
subject_set_ids.map do |set_id|
set_subject_ids = SetMemberSubject.where(subject_set_id: set_id).pluck(:subject_id)
# UNCOMMMENT ONE OF THESE, I DO A SANITY CHECK COUNT FIRST, THEN UNRETIRE
# run a count for sanity check
# SubjectWorkflowStatus.where.not(retired_at: nil).where(workflow_id: wf_id, subject_id: set_subject_ids).count
# RUN THE UNRETIRE
SubjectWorkflowStatus.where.not(retired_at: nil).where(workflow_id: wf_id, subject_id: set_subject_ids).update_all(retired_at: nil, retirement_reason: nil)
@camallen
camallen / unlock_and_reload_designator_workflow.sh
Last active April 16, 2020 16:18
Unlock and reload a designator workflow
creds="$basicUsername:$basicPassword"
host="https://designator.zooniverse.org/api/workflows"
if [ -n "$1" ]; then
curl -v --user $creds -X POST "${host}/${1}/unlock"
curl -v --user $creds -X POST "${host}/${1}/reload"
fi
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>Zooniverse Public Stream Debug</title>
<script src="https://js.pusher.com/5.1/pusher.min.js"></script>
</head>
<body>
<h1>Zooniverse Public Stream Debug</h1>
<p>
See the console log statements for the json event payloads.