Skip to content

Instantly share code, notes, and snippets.

View soffes's full-sized avatar

Sam Soffes soffes

View GitHub Profile
// From https://stackoverflow.com/a/58985069/118631
@available(macOS 10.15, *)
func canRecordScreen() -> Bool {
let runningApplication = NSRunningApplication.current
let processIdentifier = runningApplication.processIdentifier
guard let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID)
as? [[String: AnyObject]] else
{
@soffes
soffes / optional_protocol.swift
Last active January 6, 2024 07:22
Checking for the presence of an optional method in a protocol
import Foundation
@objc protocol Foo {
optional func say() -> String
}
class Doesnt: NSObject, Foo {
}
class Does: NSObject, Foo {
@soffes
soffes / UISplitViewController+Soffes.swift
Created June 8, 2016 22:23
Easily access master and detail view controllers on UISplitViewController
import UIKit
extension UISplitViewController {
convenience init(masterViewController: UIViewController, detailViewController: UIViewController) {
self.init()
viewControllers = [masterViewController, detailViewController]
}
var masterViewController: UIViewController? {
return viewControllers.first
@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 / 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',

Objective-C Coding Convention and Best Practices

Most of these guidelines are to match Apple's documentation and community-accepted best practices. Some are derived some personal preference. This document aims to set a standard way of doing things so everyone can do things the same way. If there is something you are not particularly fond of, it is encouraged to do it anyway to be consistent with everyone else.

This document is mainly targeted toward iOS development, but definitely applies to Mac as well.

Operators

NSString *foo = @"bar";
@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 / CLLocationCoordinate2D+Equatable.swift
Last active October 4, 2023 18:50
Add Equatable to CLLocationCoordinate2D
import CoreLocation
extension CLLocationCoordinate2D: Equatable {}
public func ==(lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
}
@soffes
soffes / Readme.markdown
Created July 3, 2018 23:25 — forked from calebd/Readme.markdown
Run Loop Source

CFRunLoopSource is cool. It lets you build behavior similar to the mechanisms that drive setNeedsLayout and setNeedsDisplay in UIKit.

I found myself in need of something like this a couple of times. It's great to know that no matter how many times I say I need to update something, I will get a single callback at the end of the run loop that gives me a chance to perform my work.

Here is a little Swift wrapper that makes the API easier to deal with.


Updated for Swift 4

@soffes
soffes / gist:3428401
Created August 22, 2012 19:00
Recruiter Reply

Thanks you for your inquiry.

I am only looking for contract work. My rate is one thousand dollars an hour ($1,000/hr). I charge ten thousand dollars ($10,000) for referrals.

If this does not fit the positions you are looking for, please remove me from your list.

Thanks,

Sam