Skip to content

Instantly share code, notes, and snippets.

Helping launch iOS apps in the App Store with Turbo Native and Ruby on Rails.

Joe Masilotti joemasilotti

Helping launch iOS apps in the App Store with Turbo Native and Ruby on Rails.
View GitHub Profile
joemasilotti / Endpoint.swift
Last active May 28, 2023 16:54
A Rails-like environment helper for iOS apps, from
View Endpoint.swift
import Foundation
enum Environment: String {
case development, staging, production
extension Environment {
static var current: Environment {
if isAppStore {
return .production
joemasilotti / ExampleView.swift
Created March 1, 2023 01:15
An idea to make interaction with design constants more natural
View ExampleView.swift
struct ExampleView: View {
var body: some View {
VStack(spacing: .default) {
HStack(spacing: .xl) {
Text("Is this crazy?")
.font(.system(size: .lg, weight: .semibold))
joemasilotti / show.html.erb
Created October 19, 2022 20:51
Tailwind CSS v3.2 data attribute variants + Stimulus
View show.html.erb
<div data-controller="toggle">
<button type="button" data-action="toggle#toggle">Toggle</button>
<div data-toggle-target="element" data-expanded="false" class="data-[expanded=false]:hidden">
Here is some toggle-able content!
joemasilotti / .Pay subscription
Last active August 16, 2022 13:40
Pay subscription changes
View .Pay subscription

Goal: send a notification when a customer subscribes, churns, pauses, etc.

This is the barebones working version. Is there something I'm missing in Pay that could help with this?

If not, happy to clean it up and submit a PR if it will be valuable for others.

Note: This first-pass implementation is ugly, but the tests pass. There is obviously a lot to improve in terms of code quality, but my bigger focus is on the direction and idea.

joemasilotti / result_type.rb
Last active May 25, 2022 02:50
View result_type.rb
module ResultType
extend ActiveSupport::Concern
module ClassMethods
def define_type(type)
define_method "#{type}?" do
joemasilotti / cold_message.rb
Created April 27, 2022 03:08
Service layer extraction
View cold_message.rb
# AFTER the refactor
class ColdMessage
class BusinessBlank < StandardError; end
class MissingSubscription < StandardError; end
class ExistingConversation < StandardError
attr_reader :conversation
joemasilotti / sidekiq_policy.rb
Created December 22, 2021 02:22
ActiveSupport::EnvironmentInquirer example
View sidekiq_policy.rb
class SidekiqPolicy
attr_reader :user, :environment
def initialize(user, environment: Rails.env)
@user = user
@environment = environment
def visible?
user.admin? || environment.development?
joemasilotti / HTTP.swift
Last active March 25, 2021 21:29
Combine-powered HTTP client with success and failure JSON decoding
View HTTP.swift
enum HTTP {
struct Response<T> {
let value: T
let headers: [AnyHashable: Any]
enum HTTPError<T: LocalizedError>: LocalizedError {
case failedRequest
case invalidResponse
case invalidRequest(T)
joemasilotti /
Created March 4, 2021 23:10
Turbolinks + Turbo Native - Generic form handling with Stimulus

Turbolinks + Turbo Native - Generic form handling with Stimulus

These three files show how to handle forms with (legacy) Turbolinks in your Rails app with the new Turbo Native adapters.

  1. The Rails controller renders the form partial with an :unprocessable_entity status when encountering a form validation error
  2. The form is submitted via AJAX (local: false or remote: true depending on your Rails version)
  3. This is caught via the ajax:error->form#onError Stimulus action
  4. The Stimulus controller replaces the form's contents with the server-sided rendered HTML
  5. The native app is informed when the redirect occurs on a succesful submission
joemasilotti / ScriptMessageEnum.swift
Created February 10, 2021 14:59
Two approached to a Swift enum with associated type
View ScriptMessageEnum.swift
// Enum with manual parsing.
enum ScriptMessage {
case registerForRemoteNotifications
case showBackButton(url: URL)
case signOutCompleted
init?(body: [String: Any]) {
switch body["name"] as? String {
case "registerForRemoteNotifications":
self = .registerForRemoteNotifications