Skip to content

Instantly share code, notes, and snippets.

View ramonrails's full-sized avatar
💭
Available to build SaaS, PaaS, MVP, consult and mentor

Ram ramonrails

💭
Available to build SaaS, PaaS, MVP, consult and mentor
View GitHub Profile
@ramonrails
ramonrails / fasterlane.sh
Last active December 19, 2022 16:04
fastlane deployment helper
# fastlane automated
# https://fastlane.tools/
#
function fasterlane {
# no arguments received? tell usage
if [ -z "$1" ]; then
echo "Usage: fasterlane <lane>"
echo " (dotenv, bundler, fastlane setup required)"
else
# look for ./android directory
@ramonrails
ramonrails / ruby_console_benchmark_shortcuts.rb
Last active January 24, 2024 16:35
ruby console benchmarking shortcuts
# frozen_string_literal: true
# queries in the environment must show SQL
#
# ActiveRecord::Base.verbose_query_logs = true
ActiveRecord::Base.logger = Logger.new($stdout) if defined?(ActiveRecord)
#
# Attempts to load the given gem
#
@ramonrails
ramonrails / manage_mailgun_routes.rb
Last active July 21, 2020 07:12
auto-manage mailgun routes for email addresses from CSV file
# frozen_string_literal: true
# What? A quick script written to ensure (add, unless exists) Mailgun routes for proxy SMTP of users
# Why? because the client was doing it manually for thousands of users
# When? I saw a team member working late night punching all that routes, so decided to automate for him
# Where? based on a need in a comercial product
# How? just searched for an API, found one. automated.
#
require 'rest-client'
require 'json'
@ramonrails
ramonrails / optimizing-ruby-rails-performance.rb
Last active July 9, 2020 17:53
example: optimizing ruby/rails code for performance
# Example: optimizing the code for performance (subject to the business logic)
# Purpose: Fetch all comments where author name matches given `username`
# WARN: this is a pseudo code for demonstration purpose only
#
# assuming this is a rails controller
# bad code
class CommentsController < ApplicationController
# action
def users_comments
# FIXME: very costly on resources and performance
@ramonrails
ramonrails / incident_email_dispatch.feature
Created June 1, 2020 08:10
BDD, cucumber: Emails were dispatched in a complex setup with 16 combinations of configured emails
Feature: User receives email copies
With proxy or non-proxy setup, a user will always receive copies of emails
Background: Client, User, Alias and incdent
Given a <client>
And an <smtp> setup with a sender email address
And a user with <email> and <alias>
And an incident reported
@ramonrails
ramonrails / cucumber_example_outline.feature
Created May 10, 2020 20:19
cucumber BDD example: scenario outline with examples data table
Scenario Outline: Shipping options
Given the following shipping_options:
| description | price |
| UPS Overnight shipping | 60 |
| UPS 2 day shipping | 28 |
| UPS Ground Shipping | 16 |
And "default" coupon_code for "direct_to_consumer" group has "<_ship>" shipping
When I go to the online store
And I choose "product_complete"
And I choose "S2228"
@ramonrails
ramonrails / html_form_to_json.js
Created March 8, 2020 07:58
HTML form elements to JSON
// developer: RamOnRails.in
// purpose: fetch form data as JSON
// parameters:
// form: the form object
// arg: [optional] query selector to pick elements
// defaults: arg: "input, select, textarea"
function toJSON(form, arg = null) {
// we will capture the elements and their values in this object
let hash = {};
// arg converted to string
@ramonrails
ramonrails / .pryrc
Created November 12, 2018 06:57
Helper: pry + Apartment gem + rails console
# What is it?
# => Helper methods for Apartment::Tenant gem
# How does it work?
# * bin/rails console => auto-loads and asks to switch tenant
# * T.ask => anytime in console, to switch tenant from a list
# * T.me => same as Apartment::Tenant.current
# * T.hash => hash of tenants. Example: { 0 => "public", 1 => "tenant-a" }
# * T.names => array with all existing tenant names from DB
# * T.exists?(arg) => returns true/false if `arg` exists as tenant in DB
require "rubygems"
@ramonrails
ramonrails / puma-dev.sh
Last active September 10, 2020 18:14
puma-dev management script
#!/bin/bash
# author: ramonrails.in
# version: 1.0
# release date: 7-Aug-2017
# license: MIT
# style for output
bold=$(tput bold)
cyan=$(tput setaf 6)
@ramonrails
ramonrails / assets.rb
Created November 15, 2016 12:06
rails: dynamically pickup controller-named-assets for pre-compilation
# config/initializers/assets.rb
javascripts = [...]
stylesheets = [...]
images = [...]
fonts = [...]
# NOTE: dynamically include for precompile: controller specific .coffee, .js and .scss, .css
#
# step 1: collect controller basenames
controllers = Dir.glob(File.join(Rails.root, 'app', 'controllers', '*.rb'))