Skip to content

Instantly share code, notes, and snippets.

Avatar
📱
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
joemasilotti / Endpoint.swift
Last active May 28, 2023 16:54
A Rails-like environment helper for iOS apps, from https://masilotti.com/rails-like-endpoint-switcher-for-ios-apps/
View Endpoint.swift
import Foundation
enum Environment: String {
case development, staging, production
}
extension Environment {
static var current: Environment {
if isAppStore {
return .production
@joemasilotti
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
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!
</div>
</div>
@joemasilotti
joemasilotti / .Pay subscription notifications.md
Last active August 16, 2022 13:40
Pay subscription changes
View .Pay subscription notifications.md

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
joemasilotti / result_type.rb
Last active May 25, 2022 02:50
ResultType
View result_type.rb
module ResultType
extend ActiveSupport::Concern
module ClassMethods
def define_type(type)
define_method "#{type}?" do
true
end
end
end
@joemasilotti
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
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
end
def visible?
user.admin? || environment.development?
@joemasilotti
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
joemasilotti / .README.md
Created March 4, 2021 23:10
Turbolinks + Turbo Native - Generic form handling with Stimulus
View .README.md

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
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