Skip to content

Instantly share code, notes, and snippets.

Avatar
🚐
On the road

Sam Soffes soffes

🚐
On the road
View GitHub Profile
@soffes
soffes / UIDevice+Environment.swift
Last active November 9, 2021 21:12
Find the push environment of a device. (It doesn't actually reference `UIDevice` anywhere but this seemed like a good place to put it.)
View UIDevice+Environment.swift
// From my answer https://stackoverflow.com/a/69905152/118631
import UIKit
public extension UIDevice {
enum PushEnvironment: String {
case unknown
case development
case production
}
View lol.rb
def this(_); end
def is(_); end
def fine; puts 'chaos' end
this is fine
View keybase.md

Keybase proof

I hereby claim:

  • I am soffes on github.
  • I am soffes (https://keybase.io/soffes) on keybase.
  • I have a public key ASCysfuxJROh3gB1FpEjcPIZmgCaOnFECNl8mGu3r0ozYQo

To claim this, I am signing this object:

@soffes
soffes / UIFont+Monospaced.swift
Created July 27, 2021 18:17
Monospaced numbers in iOS 15 beta 4
View UIFont+Monospaced.swift
import UIKit
extension UIFont {
public func withMonospacedNumbers() -> Self {
let monospacedFeature: [UIFontDescriptor.FeatureKey: Any]
if #available(iOS 15.0, *) {
monospacedFeature = [
.type: kNumberSpacingType,
.selector: kMonospacedNumbersSelector
@soffes
soffes / Example.swift
Last active April 1, 2021 21:33
KeyboardLayoutGuide
View Example.swift
override func viewDidLoad() {
super.viewDidLoad()
let keyboardGuide = KeyboardLayoutGuide()
view.addLayoutGuide(keyboardGuide)
NSLayoutConstraint.activate([
someTextField.bottomAnchor.constraint(lessThanOrEqualTo: view.safeAreaLayoutGuide.bottom, constant: -8),
someTextField.bottomAnchor.constraint(lessThanOrEqualTo: keyboardGuide.topAnchor, constant: -8),
])
@soffes
soffes / Gemfile
Created March 11, 2021 15:35
Along's Gemfile
View Gemfile
# frozen_string_literal: true
source 'https://rubygems.org'
ruby '3.0.0'
# Instead of depending on `rails`, I just add the gems I need below
rails_version = '>= 6.1.0'
# Active Record from Rails
@soffes
soffes / test_case.rb
Created March 11, 2021 15:01
Simple ActiveRecord query counter
View test_case.rb
class TestCase < ActiveSupport::TestCase
def setup
super
DatabaseCleaner.start
@queries = []
ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, payload|
@queries << payload[:sql] unless payload[:name].in? %w[CACHE SCHEMA]
end
end
@soffes
soffes / fib.rb
Created March 3, 2021 02:56
Fibonacci without recursion
View fib.rb
# From this delightful video https://www.youtube.com/watch?v=ghxQA3vvhsk
PHI = (1 + Math.sqrt(5)) / 2
def fib(n)
(((PHI**n) - ((-1 / PHI)**n)) / Math.sqrt(5)).to_i
end
(1...10).map { |n| fib(n) }
# => [1, 1, 2, 3, 5, 8, 13, 21, 34]
@soffes
soffes / Decoders+JSON.swift
Last active January 8, 2021 12:51 — forked from loudmouth/Decode Array<Any> and Dictionary<String, Any> Swift
Decode Array<Any> and Dictionary<String, Any> Swift
View Decoders+JSON.swift
import Foundation
// Inspired by https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24
private struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
@soffes
soffes / SafariActivity.swift
Created October 26, 2020 22:19
Open in Safari UIActivity
View SafariActivity.swift
import UIKit
final class SafariActivity: UIActivity {
// MARK: - Properties
var url: URL?
// MARK: - UIActivity