Skip to content

Instantly share code, notes, and snippets.

@mariochavez
mariochavez / _form.html.erb
Created February 26, 2025 03:32 — forked from lazaronixon/_form.html.erb
Dropzone.js + Stimulus + Active Storage + CSS Zero (2025)
<%= form_with(model: billboard) do |form| %>
<%= tag.div class: "dropzone", data: { controller: "dropzone", dropzone_param_name_value: "billboard[images][]", dropzone_url_value: rails_direct_uploads_url, dropzone_accepted_files_value: "image/*", dropzone_max_files_value: 3, dropzone_max_filesize_value: 0.300 } do %>
<div class="dz-default dz-message flex flex-col items-center">
<%= image_tag "upload.svg", size: 28, class: "colorize-black", aria: { hidden: true } %>
<h5 class="font-semibold mbs-4">Drop files here or click to upload.</h5>
<p class="text-sm text-subtle">Upload up to 10 files.</p>
</div>
<% end %>
<div class="inline-flex items-center mbs-2 mie-1">
@mariochavez
mariochavez / commands.thor
Created July 15, 2023 20:01 — forked from KonnorRogers/commands.thor
Create post thor command
require "fileutils"
class Commands < Thor
# @example
# thor commands:create_post wrapping-lit-react-components turbo-vs-htmx
desc "create_post file", "creates a file or files based on a filepath name and prefills data."
def create_post(*files)
base_dir = "src/_posts/"
files.flatten(1).each do |file|
date = Time.now.to_s.split(" ")[0]
class Ticket < ActiveRecord::Base
belongs_to :grouper
belongs_to :user
validate :user_cant_be_blacklisted, on: :confirmation
validate :user_cant_double_book, on: :confirmation
validate :grouper_cant_be_full, on: :confirmation
validate :grouper_cant_have_occurred, on: :confirmation
@mariochavez
mariochavez / files.rb
Last active February 24, 2022 17:50
Templates
remove_file "bin/setup"
create_file "bin/setup" do
<<~EOF
#!/usr/bin/env ruby
require "fileutils"
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
@mariochavez
mariochavez / downloads_controller.rb
Created May 8, 2021 01:14 — forked from SylarRuby/downloads_controller.rb
Loop through all, zip and download from ActiveStorage
# In our gemfile:
# gem 'rubyzip'
require 'zip'
# private ?
def process_and_create_zip_file
# Simulation of an object with has_many_attached :documents
job = Job.first.documents
# Tmp folder to store the download files from S3
@mariochavez
mariochavez / Github-style-syntax-in-pages.md
Created June 21, 2020 04:53 — forked from sudara/Github-style-syntax-in-pages.md
Github style syntax highlighting in Pages.app

I like Pages.app, but don't want to deal with constantly copying and pasting code around.

Here is how I do syntax highlighting in Pages.app by pressing a key command. It's based off of this post on stack exchange.

install pygments

sudo easy_install Pygments

install github syntax

@mariochavez
mariochavez / media-query.css
Created April 9, 2020 01:11 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
@mariochavez
mariochavez / post.md
Created January 10, 2020 19:01
Cómo hacer un post

Cómo hacer un post

Escribir un post técnico puede ser una tarea compleja por diferentes razones. Primeramente está el que quizás no estemos acostumbrados a escribir en general y puede haber un poco de resistencia a hacerlo.

Cuando ya estamos convencidos de escribir, la primer pregunta es "Qué escribir?". Es muy sencillo pensar que ya todo está escrito, que no hay nada nuevo a aportar, que quizás nuestro nivel técnico no es bueno para escribir un post para otras personas.

Las dudas son válidas, pero no realistas. Si bien es posible que el tema que queremos tratar ya está escrito en múltiples posts siempre es importante e interesante el revivir un tema desde nuestro punto de vista o nuestra óptica. El nivel técnico no es tan relevante, ya que el tema o la forma de llevarlo puede ser para el nivel que tenemos o bien puede ser para ayudar a otras personas que van comenzando.

El "Qué escribir?" solamente lo podemos atacar de una manera, escribir sobre algo que nos interesa o algo en lo que trabajamos y de lo

@mariochavez
mariochavez / base_validator.js
Created June 13, 2019 19:44
Stimulus validations
export default class BaseValidator {
constructor(value, options, errorMessages) {
this.value = value
this.options = options
this.errorMessages = errorMessages
}
validate() {
return { valid: false, message: 'Implement me!'}
}
The Task
Convert an entire folder of RAW images, typically produced by DSLR camera at 300dpi and convert them all to web-ready, 72dpi JPEG's in a single bash command while utilizing all eight threads in parallel on a quad-core i5 CPU.
OS X Prerequesites
Install ImageMagick with RAW support via Homebrew.
If you don't already have Homebrew, shame on you. Grab it like so: