Skip to content

Instantly share code, notes, and snippets.

@mjmsmith
mjmsmith / Bundle+TestFlight.swift
Created October 30, 2023 21:11 — forked from lukaskubanek/Bundle+TestFlight.swift
A code snippet for detecting the TestFlight environment for a macOS app at runtime
import Foundation
import Security
extension Bundle {
/// Returns whether the bundle was signed for TestFlight beta distribution by checking
/// the existence of a specific extension (marker OID) on the code signing certificate.
///
/// This routine is inspired by the source code from ProcInfo, the underlying library
/// of the WhatsYourSign code signature checking tool developed by Objective-See. Initially,
@mjmsmith
mjmsmith / OSColor.swift
Last active February 4, 2023 21:36
Resolve dynamic colors on macOS and iOS.
import SwiftUI
// MARK: - macOS
#if os(macOS)
typealias OSColor = NSColor
extension OSColor {
func resolvedOSColor(colorScheme: ColorScheme? = nil) -> OSColor {
@mjmsmith
mjmsmith / InAppPurchaseManager.swift
Created February 21, 2019 11:18 — forked from RenGate/InAppPurchaseManager.swift
Sample implementation of In-App purchase manager class
// MIT License
//
// Copyright (c) 2019 Rostyslav Dovhaliuk
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
import Foundation
extension Data {
public init?(hexString: String) {
let utf16 = hexString.utf16
var data = Data(capacity: utf16.count / 2)
var hiIndex = utf16.startIndex
while hiIndex != utf16.endIndex {
guard let hi = Data.decodeNibble(utf16[hiIndex]),
@mjmsmith
mjmsmith / wwdc.rb
Created September 5, 2014 02:03
WWDC videos
require "date"
require "nokogiri"
require "open-uri"
builder = Nokogiri::XML::Builder.new do |xml|
xml.feed ({"xml:lang"=>"en-US", "xmlns"=>"http://www.w3.org/2005/Atom"}) {
xml.id "http://camazotz.com/wwdc.xml"
xml.link ({"rel"=>"self", "href"=>"http://camazotz.com/wwdc/index.xml"})
xml.link ({"rel"=>"alternate", "type"=>"text/html", "href"=>"https://developer.apple.com/videos/wwdc/"})
xml.title "WWDC Videos"
#!/usr/bin/env ruby
# vim: set syntax=ruby
flag = false
files = `git diff --cached --name-only --diff-filter=ACM | grep "_spec\.rb$"`.split("\n")
files.each do |file|
results = `git diff --cached #{file} | grep "^\+[^+]" | grep ":focus => true"`.split("\n").map { |r| r.sub(/^\+[\s\t]*/, '') }
if $? == 0
@mjmsmith
mjmsmith / KeychainItemWrapper.h
Created November 30, 2012 20:35 — forked from dhoerl/KeychainItemWrapper.h
KeychainItemWrapper ARCified
/*
File: KeychainItemWrapper.h
Abstract:
Objective-C wrapper for accessing a single keychain item.
Version: 1.2 - ARCified
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
@mjmsmith
mjmsmith / block_alert.rb
Created May 8, 2012 22:09
playing with RubyMotion
class BlockAlert
def initWithTitle(title, message:message)
@alert = UIAlertView.alloc.initWithTitle(title, message:message, delegate:self, cancelButtonTitle:nil, otherButtonTitles:nil)
@blocks = []
self
end
def show
@alert.show()
@mjmsmith
mjmsmith / favorite.sql
Created April 5, 2010 19:14
munge metafilter infodump for easier querying
DROP TABLE IF EXISTS favorite;
CREATE TABLE favorite (
id int(11) NOT NULL AUTO_INCREMENT,
created datetime NOT NULL,
favee_id int(11) NOT NULL,
faver_id int(11) NOT NULL,
post_id int(11) NOT NULL,
comment_id int(11) NOT NULL,
type int(11) NOT NULL,
PRIMARY KEY (id)