Skip to content

Instantly share code, notes, and snippets.

View ryenski's full-sized avatar
🎯
Focusing

Ryan Heneise ryenski

🎯
Focusing
View GitHub Profile
@ryenski
ryenski / i18n-best-practices.md
Created October 1, 2024 17:46
I18n Best Practices in Rails

I18n Best Practices

Use human-readable keys

Prefer natural language over abstracted strings for language keys. This helps to make the views easier to read and understand.

Take advantage of the fact that spaces are legal in YAML keys:

Examples

# Bad
t('.all_label')
@ryenski
ryenski / db.rake
Created May 28, 2024 16:33
Protect production environment from destructive rake tasks
desc 'Raise exception if used in production'
task protect_prod: [:environment] do
raise 'This task cannot be run in production' if Rails.env.production?
end
['db:drop', 'db:reset', 'db:seed'].each do |t|
Rake::Task[t].enhance ['protect_prod']
end
@ryenski
ryenski / json-to-csv-with-jq.md
Last active April 11, 2024 20:14
Convert json to csv with jq @csv filter

To convert json to csv with headers using jq and the @csv filter.

jq -r '[first|keys_unsorted] + map([.[]]) | .[] | @csv' example.json > converted.csv

This would work on a simple json structured like:

[
@ryenski
ryenski / one_time_code.rb
Created December 12, 2022 23:58
A small script to generate memorable one-time passcodes.
# A small script to generate memorable one-time codes.
#
# OneTimeCode.generate
# => "ubahow-idea-easy-aveda"
class OneTimeCode
def initialize(length = 12)
@length = length
@mod_result = MOD_RESULT.sample
end
@ryenski
ryenski / checkout.rb
Last active December 12, 2022 23:59
Stripe Webhooks Controller
# This example follows a Stripe webhook through the application life cycle.
# In this case, a customer has created a Checkout, which is an object in our application that acts like a shopping cart.
# It relates to the products that are being purchased and encapsulates the customer's existing record, or the data required to create a new customer.
class Checkout < ApplicationRecord
include Amountable
include BtcpayInvoice
include StripePaymentIntent
belongs_to :user, optional: true
{"version":1,"resource":"file:///Users/ryanheneise/Projects/api/src/services/fees/index.js","entries":[{"id":"DXVN.js","timestamp":1667270770299},{"id":"VJk1.js","timestamp":1667270856905},{"id":"pi2q.js","timestamp":1667271038502}]}
@ryenski
ryenski / client.rb
Last active December 16, 2024 06:28
# frozen_string_literal: true
module MxIsoagent
class Client
BOARDING_URL = Rails.configuration.mx_iso_agent['boarding_url']
CHECKOUT_URL = Rails.configuration.mx_iso_agent['checkout_url']
INVITE_CODE = Rails.configuration.mx_iso_agent['invite_code']
BOARDING_KEYS = Rails.configuration.mx_iso_agent['api_key']
BUSINESS_TYPES = [
@ryenski
ryenski / gravatar_helper.rb
Last active December 12, 2022 23:39
gravatar_helper.rb
# frozen_string_literal: true
module GravatarHelper
def gravatar_image_tag(email, attrs = {})
attrs = {
class: 'h-10 w-10 rounded-full'
}.update(attrs)
image_tag gravatar_url(email), attrs
end
@ryenski
ryenski / pix-brief.md
Last active October 14, 2019 17:42
Project Brief for PIX Portal

Project Brief for PIX Portal

We're looking for a talented and competent Ruby on Rails developer to help us re-engineer an existing app that's hard to maintain and expensive. The existing app is built using React on the frontend and Apache Airflow on the backend. We're going to re-engineer the app to make it more maintainable and remove some unneeded complexity that makes it difficult to maintain and expensive to develop.

The purpose of this app is to receive credit card processing reports, apply a markup algorithm, and then generate a report for each store based on the result.

About the app

The current process is handled by two separate apps:

# frozen_string_literal: true
# bundle exec rails runner create_accounts.rb
# An organization that the above users don't have access to
organization = Organization.find_or_create_by(slug: 'accounting-demo') do |o|
o.name = 'Accounting Demo'
o.invite_code = Rails.configuration.mx_iso_agent['invite_code']
end