Skip to content

Instantly share code, notes, and snippets.

View borama's full-sized avatar
🥕
Ready for some carrot

Matouš Borák borama

🥕
Ready for some carrot
View GitHub Profile
@borama
borama / tailwind_form_builder.rb
Last active September 17, 2024 12:02
Tailwind-styled Simple Form builder example - see https://dev.to/nejremeslnici/styling-simple-form-forms-with-tailwind-4pel for all details
# This is a thin wrapper of the Simple Form builder. It delegates rendering the resulting form fields to Simple Form
# but typically amends the Tailwind classes of the various elements in the field layout. It tightly integrates with the
# unstyled wrapper (aka `:plain`) Simple Form configuration (see `simple_form.rb`). The methods support the same syntax
# as the original Simple Form methods but enhance it to support replacing defaylt Tailwind claseses.
class Builders::TailwindFormBuilder < SimpleForm::FormBuilder
# This is the basic method for rendering `<input>` tags and their variants.
def input(attribute_name, options = {}, &block)
# The default Tailwind classes for the various parts of the Simple Form wrapper layout.
input_class = "block w-full sm:text-sm ... #{'text-gray-500 bg-gray-50' if options.dig(:input_html, :disabled)}"
@borama
borama / basic_form.html.slim
Last active December 30, 2023 03:06
Previewing Simple Form form (or any Rails template in general) in Lookbook
/ spec/components/previews/forms/simple_form_preview/basic_form.html.slim
= simple_form_for(mail_search_object, url: "/fake/search") do |f|
= f.input :to
= f.input :subject, hint: "Explanation for this field"
= f.button :submit, "Search"
@borama
borama / tachyons_to_tailwind.yml
Created February 23, 2021 19:07
The config file for the tachyons_to_tailwind.rb migration script. Useful for migrating Tachyons to Tailwind CSS. See https://dev.to/nejremeslnici/migrating-tachyons-to-tailwind-css-part-i-ich for more context.
# media query: tachyons postfix (-mq) => tailwind prefix (mq:)
variants:
ns: sm
l: lg
# tachyons_class => tailwind_class
replacements:
# paddings
pa0: p-0
@borama
borama / tachyons_to_tailwind.rb
Created February 19, 2021 13:34
Script to replace Tachyons utility classes with their Tailwind counterparts, as configured via the YAML config file. Please find more context at https://dev.to/nejremeslnici/migrating-tachyons-to-tailwind-css-part-i-ich.
#!/bin/env ruby
# Migrate classes in the whole project using configuration in `tachyons_to_tailwind.yml`.
# Intended for migrating Tachyons utility CSS to Tailwind CSS.
#
# See https://dev.to/nejremeslnici/migrating-tachyons-to-tailwind-css-part-i-ich for more context.
#
# To use this, do the following:
#
# Make this scrint executable: `chmod a+x tachyons_to_tailwind.rb`.
@borama
borama / compare_classes.rb
Last active August 25, 2022 23:17
A script to compare the classes in two CSS files. Useful for migrating utility CSS systems, such as Tachyons to Tailwind. Please find all the context here: https://dev.to/nejremeslnici/migrating-tachyons-to-tailwind-css-part-i-ich.
#!/bin/env ruby
# Compare classes between Tachyons & Tailwind
#
# Please read https://dev.to/nejremeslnici/migrating-tachyons-to-tailwind-css-part-i-ich for more context.
#
# To use this, do the following:
# Install css_parser gem (https://github.com/premailer/css_parser)
# - `gem install css_parser`
#
@borama
borama / podpisy.rb
Last active April 14, 2020 05:10
Skript pro stažení kompletní petice z webu petice.com
require "nokogiri"
require "open-uri"
require "csv"
# set the petition_name, e.g. for https://www.petice.com/puste_tatinky_k_porodu:
petition_name = "puste_tatinky_k_porodu"
# if you want to add later signatures, set the first page number to retrieve
from_page = 1
rows_per_page = 100
@borama
borama / autoarchive-tables.sh
Created February 7, 2020 14:57
Shell script to automate MySQL tables time-based archival
#!/bin/bash
set -e
database="MY_DATABASE"
altered_tables=0
function fatal {
echo "FATAL: $1" >&2
echo "Exiting now." >&2
@borama
borama / export-partition.sh
Last active June 9, 2023 08:06
Shell script to export data from the given table partition and delete it aferwards
#!/bin/bash
# "panic button" when run in a for loop:
# exit
database="MY_DATABASE"
export_dir="/mnt/backups/my-archive"
set -e
@borama
borama / run_ghost.sh
Created February 6, 2020 15:30
Helper shell script for running the gh-ost tool
#!/bin/bash
function usage {
echo "Use ./run_ghost.sh table_name 'alter_command' [other_ghost_args]"
exit 1
}
database="MY_DATABASE_NAME"
table=$1
@borama
borama / ruby_gems_age.rb
Last active October 25, 2023 21:03
A script that collects and prints info about the age of all ruby gems in your project, see https://dev.to/borama/how-old-are-dependencies-in-your-ruby-project-3jia
#!/bin/env ruby
#
# Collects info about the age of all gems in the project
#
require "json"
require "date"
bundle = `bundle list`
yearly_stats = {}