Skip to content

Instantly share code, notes, and snippets.

View zealot128's full-sized avatar

Stefan Wienert zealot128

View GitHub Profile
@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|
<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
@zealot128
zealot128 / rails-models-to-typescript-schema.rb
Last active February 18, 2024 12:11
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
@zealot128
zealot128 / gitlab_migrate.sh
Last active December 29, 2023 21:59
Gitlab migrate omnibus installation to new server
#!/bin/bash
# ATTENTION: COPY&PASTE RUN EVERY LINE BY HAND AND VERIFY THE OUTPUT
# the old host, must have direct ssh access
# generate ssh-keygen on new host and copy over into authorized_keys
gitlab='root@1.2.3.4'
# Stopping everything on remote system
echo "$gitlab - Gitlab Stop"
ssh $gitlab "gitlab-ctl stop nginx"
- Check out
- install modern terraform version
- ``terraform init``
- get a Hetzner key,
- set it before run: ``` export TF_VAR_hcloud_token=...```
- ``terraform plan``
- ``terraform apply``
@zealot128
zealot128 / ActiveStorageDocxPreviewer.md
Last active September 18, 2023 11:18
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 / README.md
Last active July 25, 2023 19:54
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 / lspconfig-tailwind-rubyfiles.lua
Last active April 6, 2023 13:20
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 / README.md
Last active April 6, 2023 12:14
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,