Skip to content

Instantly share code, notes, and snippets.

View soffes's full-sized avatar

Sam Soffes soffes

View GitHub Profile
@soffes
soffes / convert_amazon_orders.rb
Created November 4, 2023 18:04
Convert Amazon orders export JSON to CSV
require 'json'
require 'csv'
# There are more, but these are the ones I care about
keys = [
'Order Date',
'Order ID',
'Currency',
'Unit Price',
'Total Owed',
@soffes
soffes / check-jobs.rb
Created October 27, 2023 01:15
Some messy scripts for deleting AWS Glacier vaults
require 'json'
ACCOUNT_ID = ''
data = JSON.load(File.read('jobs.json'))
data.each do |job|
unless job[['completed']]
result = JSON.load(`aws glacier list-jobs --account-id="#{ACCOUNT_ID}" --region="#{job['region']}" --vault-name="#{job['vault']}"`)['JobList'].detect { |i| i['JobId'] == job['job'] }
job['completed'] = result['Completed']
end
@soffes
soffes / README.md
Last active November 16, 2023 13:21
Lame attempt at finding the best Wordle starting words

Starting Wordle

Lame attempt at trying to find the best starting word. I found the word list in some blog post. This attempts to find the best starting words by giving each letter in the word score from the percentage of words that share a letter in that position.

The 5 best:

  • slate
  • sauce
  • slice
  • shale
@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.)
// From my answer https://stackoverflow.com/a/69905152/118631
import UIKit
public extension UIDevice {
enum PushEnvironment: String {
case unknown
case development
case production
}
def this(_); end
def is(_); end
def fine; puts 'chaos' end
this is fine

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