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]
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:
@mariochavez
mariochavez / testing_front_end_rspec_capybara.md
Created January 10, 2018 20:04 — forked from juliocesar/testing_front_end_rspec_capybara.md
Testing front-end for a Sinatra app with RSpec and Capybara

Testing front-end for a Sinatra app with RSpec and Capybara

I've used Cucumber quite a bit on my last job. It's an excellent tool, and I believe readable tests are the way to the future. But I could never get around to write effective scenarios, or maintain the boatload of text that the suite becomes once you get to a point where you have decent coverage. On top of that, it didn't seem to take much for the suite to become really slow as tests were added.

A while ago I've seen a gist by Lachie Cox where he shows how to use RSpec and Capybara to do front-end tests. That sounded perfect for me. I love RSpec, I can write my own matchers when I need them with little code, and it reads damn nicely.

So for my Rails Rumble 2010 project, as usual, I rolled a Sinatra app and figured I should give the idea a shot. Below are my findings.

Gemfile