Skip to content

Instantly share code, notes, and snippets.

View jubishop's full-sized avatar
🎼
Making a podcast app.

Justin Bishop jubishop

🎼
Making a podcast app.
View GitHub Profile
private var duration: CMTime? {
guard let timeComponents = rssEpisode.iTunes.duration?.split(separator: ":").reversed(),
timeComponents.count <= 3
else { return CMTime.zero }
var seconds = 0
for (position, value) in timeComponents.enumerated() {
guard let value = Int(value) else { return CMTime.zero }
var multiplier = 1
for _ in 0..<position { multiplier *= 60 }
@jubishop
jubishop / tests.swift
Created December 24, 2024 17:23
queue tests
import Foundation
import GRDB
import Testing
@testable import PodHaven
@Suite("of Queue repo tests")
actor QueueTests {
private let repo: Repo
private let podcast: Podcast
@jubishop
jubishop / file.swift
Last active December 24, 2024 17:20
queue management
// MARK: - Queue Management
func dequeue(_ episodeID: Int64) async throws {
try await appDB.db.write { db in
guard let oldPosition = try _fetchOldPosition(db, for: episodeID) else {
return
}
try _moveInQueue(db, episodeID: episodeID, from: oldPosition, to: Int.max)
try Episode.filter(id: episodeID)
@jubishop
jubishop / generics.swift
Created December 11, 2024 17:22
generic swift status AVPlayer
protocol StatusObservable: NSObject, Sendable {
associatedtype Status: Equatable, Sendable
var status: Status { get }
var error: Error? { get }
}
extension AVPlayer: @retroactive Sendable {}
extension AVPlayer: StatusObservable {
typealias Status = AVPlayer.Status
}
import SwiftUI
struct HTMLText: View {
let html: String
var customColor: Color = .primary
var font: Font = .body
var body: some View {
if let data = html.data(using: .utf8),
let nsAttributedString = try? NSMutableAttributedString(
@jubishop
jubishop / expect.swift
Last active November 27, 2024 08:43
expect() testing
// Copyright Justin Bishop, 2024
import Foundation
import Testing
public actor Fulfillment {
private var _fulfilled: Bool = false
public func callAsFunction() {
_fulfilled = true
}
@jubishop
jubishop / expectation.swift
Created November 26, 2024 22:00
Swift Asynchronous Testing
class Fulfillment {
var count: Int = 0
func callAsFunction(count: Int = 1) {
self.count += 1
}
}
func expectation(
_ comment: Comment,
timeout: TimeInterval = 0.1,
#!/usr/bin/env ruby
require 'set'
def parse(filename)
if filename.start_with?('clip')
return filename.match(/^clip-(\d+)-(\d+)-(\d+)\s+(\d+);(\d+);(\d+)/).captures
else
return filename.match(/^(\d+)-(\d+)-(\d+)\s+(\d+)\.(\d+)\.(\d+)/).captures
end
#!/usr/bin/env ruby
require 'set'
files = Dir.glob('**/*.ARW') + Dir.glob('**/*.RAF')
files.each { |old_file|
new_file = "#{File.join(File.dirname(old_file), File.basename(old_file, File.extname(old_file)))}.heic"
if File.exist?(new_file)
puts "Deleting #{old_file}"
File.delete(old_file)
require 'sinatra'
get '/long_process' do
child_pid = Process.fork do
# hard work is done here...
sleep 10
Process.exit
end