Skip to content

Instantly share code, notes, and snippets.

View zealot128's full-sized avatar

Stefan Wienert zealot128

View GitHub Profile
@zealot128
zealot128 / ActiveStorageDocxPreviewer.md
Last active August 7, 2025 00:15
Activestorage Docx Previewer

Docx (and other Office doc) previewer support for ActiveStorage

Converts all document formats using LibreOffice first to PDF and then to an image, using build-in pdf previwer of ActiveStorage

  • needs: unoconv, a command line tool which uses libreoffice, e.g. apt install unoconv
  • needs a PDF converter, because libreoffice will make a pdf from the office document, Mupdf oder Poppler are already integrated into ActiveStorage, and poppler is free to use, e.g. apt install poppler-utils
@zealot128
zealot128 / simple_form.rb
Created August 13, 2022 14:50
Rails simple_form Tailwind Daisy UI config
# frozen_string_literal: true
#
# Uncomment this and change the path if necessary to include your own
# components.
# See https://github.com/heartcombo/simple_form#custom-components to know
# more about custom components.
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
#
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
@zealot128
zealot128 / apply.diff
Created April 22, 2025 08:20
Kamal on Rails app - Diff
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..325bfc0
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,51 @@
+# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
+
+# Ignore git directory.
+/.git/
@zealot128
zealot128 / README.md
Last active April 5, 2025 19:35
Gitlab runner with docker by cloud init on Hetzner Cloud

Quick Terraform script to deploy Gitlab runner with docker onto Hetzner Cloud (Hcloud)

  1. Create other terraform stuff
  • tf-backend,
  • creds.auto.tfvars with hcloud_token
  • ssh key: mkdir keys; ssh-keygen -f id_rsa
  1. modify cloudinit.yml:
  • change gitlab url
  • ADD_YOUR_REGISTRY_TOKEN -> Set to the Gitlab Runner Registration Token
  • Add more allowed images/services, if using gitlab registry, like that: registry.myinstance.com/administrators/docker-images/*, change base image etc.
@zealot128
zealot128 / README.md
Last active January 8, 2025 15:15
ActiveStorage migration guide and caveats from Carrierwave (similar starting point for Paperclip)

Migrate Carrierwave to ActiveStorage

Migrate, e.g. organisation.logo (Carrierwave "LogoUploader") to organisation.logo2 (ActiveStorage)

require 'migrate_attachment'
migrate_attachment!(
  klass: Organisation, 
  attachment_attribute: :logo, 
  carrierwave_uploader: LogoUploader, 
@zealot128
zealot128 / lspconfig-tailwind-rubyfiles.lua
Last active December 18, 2024 22:46
Neovim Tailwindcss with custom files (Ruby, ViewComponents, Phlex etc.)
local lspconfig = require('lspconfig')
-- https://github.com/tailwindlabs/tailwindcss-intellisense/issues/737
lspconfig.tailwindcss.setup {
--on_attach = on_attach,
--flags = lsp_flags,
filetypes = { "aspnetcorerazor", "astro", "astro-markdown", "blade", "clojure", "django-html", "htmldjango", "edge", "eelixir", "elixir", "ejs", "erb", "eruby", "gohtml", "haml", "handlebars", "hbs", "html", "html-eex", "heex", "jade", "leaf", "liquid", "markdown", "mdx", "mustache", "njk", "nunjucks", "php", "razor", "slim", "twig", "css", "less", "postcss", "sass", "scss", "stylus", "sugarss", "javascript", "javascriptreact", "reason", "rescript", "typescript", "typescriptreact", "vue", "svelte", "ruby" },
init_options = {
userLanguages = {
@zealot128
zealot128 / Bootstrap4migration.md
Last active October 1, 2024 20:38
Bootstrap 3 -> 4 simplistic migration script (Rails based paths and file types)
  1. Run against code base to make the most labor intensive work
  2. Totally redo navigation from scratch
  3. maybe add -xs stuff, like col-xs- or btn-xs, thats missing from BS4
@zealot128
zealot128 / rails-models-to-typescript-schema.rb
Last active July 1, 2024 16:05
Simple ruby script to generate Active Record Typescript information with enums + associations
# USAGE:
# rails runner rails-models-to-typescript-schema.rb > app/javascript/types/schema.d.ts
Rails.application.eager_load!
models = ActiveRecord::Base.descendants.reject { |i| i.abstract_class? }
belongs_to = true
has_many = true
<template lang='pug'>
div.drop-zone(:class='{dragging: isDragging }'
@dragover.prevent='dragover'
@dragenter.prevent='dragover'
@drop.prevent.stop='onDrop'
@dragleave.prevent='dragleave')
div(:class='{ hidden: uploadInProgress }' @click='openFileBrowser')
slot
i {{label}}
input(type='file' :multiple='multiple' ref='input' style='display: none')
@zealot128
zealot128 / update_hostkeys.sh
Last active February 23, 2024 09:31
Ansible: remove known hostkey from all hosts to fix mismatching host key after host recreation
# Needs jq
hosts=`ansible-inventory --list | awk -F': "' '/ansible_host/ {print $2}' | cut -d'"' -f1`
echo $hosts | xargs -I {} ssh-keygen -R {}
echo $hosts | xargs -I {} ssh-keyscan {} >> ~/.ssh/known_hosts