Skip to content

Instantly share code, notes, and snippets.

View joemasilotti's full-sized avatar
📱
Helping Rails developers build iOS and Android apps with Turbo Native.

Joe Masilotti joemasilotti

📱
Helping Rails developers build iOS and Android apps with Turbo Native.
View GitHub Profile
@joemasilotti
joemasilotti / sidekiq_policy.rb
Created December 22, 2021 02:22
ActiveSupport::EnvironmentInquirer example
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 / Multiple sheets in SwiftUI.md
Last active October 13, 2021 03:20
Multiple sheets in SwiftUI
@joemasilotti
joemasilotti / HTTP.swift
Last active March 25, 2021 21:29
Combine-powered HTTP client with success and failure JSON decoding
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

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
// 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
@joemasilotti
joemasilotti / TestVisitDelegate.swift
Created December 28, 2020 18:44
Using #function to record messages sent to Swift test doubles
class TestVisitDelegate: VisitDelegate {
func visitDidStart() {
record(#function)
}
func visitDidComplete() {
record(#function)
}
// MARK: Testing verification helpers.
@joemasilotti
joemasilotti / .UI tests without UI Testing experiment.md
Last active December 6, 2020 13:46
UI tests without UI Testing experiment

UI tests without UI Testing experiment

This gist is a small experiment to see if there's an "in-between" for testing iOS applications. More feature-level than XCTest but not as heavy handed (or slow and brittle) as UI Testing.

The general idea is to provide an API similar to UI Testing but be able to spin up any controller on the fly. By putting the controller inside of a window the test behaves a bit more like the real app.

Currently, only two methods are explored: finding labels and buttons. An obvious omission is searching for the view recursively. A perhaps less obvious omission is still being able to tap disabled buttons.

This extends on my thoughts in a recent blog, Testing the UI without UI Testing in Swift.

@joemasilotti
joemasilotti / killsim.sh
Last active October 17, 2020 11:28
Kill iOS Simulator Zombie Processes
ps aux | grep _sim | grep -v grep | awk '{print $2}' | xargs kill -9 2>/dev/null
@joemasilotti
joemasilotti / ContentView.swift
Last active August 4, 2020 19:27
SwiftUI List/ForEach with bindings
import SwiftUI
struct ContentView: View {
@ObservedObject private var signalStore = SignalStore()
var body: some View {
VStack {
List(signalStore.all) { signal in
SignalView(signal: self.signalStore.binded(signal: signal))
}
@joemasilotti
joemasilotti / About.md
Last active March 26, 2020 09:35
Building NSURL Queries with NSURLQueryItems and NSURLComponents