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 / .rouge-line-focusing.md
Last active June 19, 2024 03:59
Rouge syntax highlighting with line focusing

This gist shows how I'm using Rouge to highlight individual lines of code. On top of the existing syntax highlighting.

I'm using Sitepress which uses markdown-rails under the hood. But this should be applicable to any application rendering markdown with Redcarpet - sub out ApplicationMarkdown as your renderer.

Append @[] when setting the language in a fenced code block to highlight lines of code. Dashes will cover the range, inclusive. Commas will highlight each line.

Examples:

```swift@[4-6]
@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/
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
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
<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

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