Skip to content

Instantly share code, notes, and snippets.

@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]
@mariochavez
mariochavez / migration.md
Created February 6, 2017 17:30
RSpec to Minitest

These are the scripts that I used to migrate from RSpec to Minitest in a Rails aplication.

It is expected for the test suite to be in RSpec 3.x sintax.

  1. Install rename library from Homebrew
  2. Remove RSpec/TestUnit from Gemfile
  3. Add minitest-rails gem
  4. Rename spec forder to test
  5. Add a test_helper.rb file
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 / 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!'}
}
@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 / 01-Notas.md
Last active June 17, 2020 18:18
Usando Docker con Rails

Usando Docker con Rails para hacer deploy a Producción

Instalar Docker

Hay que seguir las notas en https://docs.docker.com/installation/ para el sistema operativo que esten ejecutando.

Utilizando un contenedor para Postgresql

Vamos a utilizar un container ya listo para trabajar con Postgresql. El siguiente comando se encarga de descargar el container y de ejecutarlo. Si es necesario cambiar el valor de las variables POSTGRES_PASSWORD y POSTGRES_USER a unos más adecuados

$ docker run --name db -e POSTGRES_PASSWORD=manager -e POSTGRES_USER=rails -d postgres
@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