Skip to content

Instantly share code, notes, and snippets.

View jmdfm's full-sized avatar
💭
😺

John McDowall jmdfm

💭
😺
View GitHub Profile
@rameerez
rameerez / kamal-production-server-setup.sh
Last active March 30, 2025 11:55
Set up a Ubuntu server to deploy Kamal 2.x Docker containers to, hardened security and production ready
#!/bin/bash
# Production Docker Host Hardening Script v2
# For Ubuntu Server 24.04 LTS (Noble)
# Suitable for both Kamal deployment and builder hosts
set -euo pipefail
IFS=$'\n\t'
# --- Constants ---
@srcrip
srcrip / tailwindForms.js
Created September 21, 2024 15:47
This is just a copy-and-paste of the Tailwind Forms plugin that you can actually edit/customize/maintain + JSDoc types.
// Tailwind plugin for forms.
// Basically: https://github.com/tailwindlabs/tailwindcss-forms/blob/main/src/index.js
// But with a few changes. And it's easier to maintain this way.
const svgToDataUri = require("mini-svg-data-uri")
const plugin = require("tailwindcss/plugin")
const defaultTheme = require("tailwindcss/defaultTheme")
const colors = require("tailwindcss/colors")
const [baseFontSize, { lineHeight: baseLineHeight }] =
defaultTheme.fontSize.base
const { spacing, borderWidth, borderRadius } = defaultTheme
@Shpigford
Shpigford / permissions.sql
Created September 8, 2024 18:06
Digital Ocean Postgres Permissions
REVOKE ALL ON DATABASE demo_database FROM demo_user;
GRANT CONNECT ON DATABASE demo_database TO demo_user;
GRANT USAGE, CREATE ON SCHEMA public TO demo_user;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO demo_user;
GRANT USAGE ON ALL SEQUENCES IN SCHEMA public TO demo_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO demo_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE ON SEQUENCES TO demo_user;
from transformers import AutoTokenizer, AutoModel
import torch
# MODEL CKPT is downloaded from: "jinaai/jina-embeddings-v2-base-en" # has context len of 8192
MODEL_CKPT = "/Users/rohan/3_Resources/ai_models/jina-embeddings-v2-base-en"
def recursive_splitter(text: str, separators: list[str], chunk_size: int) -> list[str]:
if len(separators) == 0:
words = text.strip().split(' ')
@Duartemartins
Duartemartins / batchtrequest.rb
Last active May 2, 2024 19:57
Google Search Console Batch Index Requesting
require 'googleauth'
require 'json'
require 'net/http'
require 'uri'
require 'nokogiri' # to parse the sitemap
require 'cgi'
SCOPES = ['https://www.googleapis.com/auth/indexing']
ENDPOINT = 'https://indexing.googleapis.com/v3/urlNotifications:publish'
JSON_KEY_FILE = 'page-indexing-000000-26ca419af0a4.json' #replace with your json key file
@jmdfm
jmdfm / aws.tf
Created November 16, 2023 03:34
The Terraform config to setup a managed LB, Firewall, PSQL DB, Redis and droplets on DO, with bonus ECR on AWS.
resource "aws_ecr_repository" "repo" {
name = "${var.product_name}-app"
}
resource "aws_ecr_lifecycle_policy" "ecr-lifecycle-policy" {
repository = aws_ecr_repository.repo.name
policy = jsonencode({
rules = [
{
@fractaledmind
fractaledmind / has_many_attached.rb
Created October 25, 2023 20:21
Vanilla Rails isomorphic attachment validations
# /app/models/concerns/has_many_attached.rb
module HasManyAttached
extend ActiveSupport::Concern
class_methods do
def has_many_attached(name, dependent: :purge_later, service: nil, strict_loading: false, **options)
super(name, dependent: :purge_later, service: nil, strict_loading: false)
if options[:file_types].any?
validate "validate_#{name}_file_types".to_sym
@huksley
huksley / mrsk-accessory-docker-registry.yml
Last active August 13, 2023 10:56
Run docker registry as mrsk accessory
registry-github: &docker
username: username
password:
- DOCKER_TOKEN
registry-internal: &internal
server: registry.example.com
username: testuser
password: testpassword123
# This uses YAML magic and Ruby template language to select registry on the fly
registry: *<%= ENV["MRSK_REGISTRY"] || 'internal' %>
@huksley
huksley / mrsk.md
Last active January 12, 2024 17:24
mrsk - the missing manual

MRSK

This documentation adds important additions to the docs for mrsk deploy tool (see github.com/mrsked/mrsk)

Destination flag

You can use mrsk deploy --destination staging

This will read config/deploy.yml and config/deploy.staging.yml files, and also will read .env.staging file if it exists.

@bogsen
bogsen / fix-plex-hdr-subtitles.md
Last active September 6, 2024 10:48
Fix Plex transcoding HDR videos very slowly when burning subtitles in at the same time

This workaround should no longer be necessary with newer Plex versions: https://forums.plex.tv/t/subtitle-burn-in-improvement-test-build/884481


Old content left here for reference:

What?

For some reason, although Plex supports hardware-accelerated HDR tone mapping, Plex decides not to use it when subtitles need to be burned in. This results in extremely slow transcoding on hardware that should