Skip to content

Instantly share code, notes, and snippets.

View GregoryMaks's full-sized avatar

Gregory Maksiuk GregoryMaks

View GitHub Profile
@GregoryMaks
GregoryMaks / fileExtensionsForUTType.swift
Created February 16, 2022 17:29
File extensions for specified UTType and all its descenders
import UniformTypeIdentifiers
let allTypes: [UTType] = [
.item,
.content,
.compositeContent,
.diskImage,
.data,
.directory,
@GregoryMaks
GregoryMaks / RunningApplicationsObserver.swift
Created August 1, 2023 10:32
Observes current running applications through `NSWorkspace` and notifies if any of the requested applications change their running status
import AppKit
import Combine
import CombineExt
import Foundation
import SharedUtils
// sourcery: Automockable
protocol RunningApplicationsObserverType {
func observeApplicationsRunningStatus(bundleIdentifiers: [String]) -> AnyPublisher<Void, Never>
}
class Solution {
func networkDelayTime(_ times: [[Int]], _ n: Int, _ k: Int) -> Int {
var graph: [Int: [(Int, Int)]] = [:]
for time in times {
var edges = graph[time[0]] ?? []
edges.append((time[1], time[2]))
graph[time[0]] = edges
}
struct HeapNode: Comparable {
// Time: O(MxN*3^L)
// Space: O(L), don't count matrix change
class Solution {
let dt: [[Int]] = [[0, 1], [0, -1], [1, 0], [-1, 0]]
func exist(_ board: [[Character]], _ word: String) -> Bool {
var board = board
let word: [Character] = Array(word)
var locs: [[Int]] = []
// Time: O(NxK)
// Space: O(NxK) - need to store the results somewhere
class Solution {
func mergeKLists(_ lists: [ListNode?]) -> ListNode? {
var tops = lists.compactMap { $0 ?? nil }
var resultRoot: ListNode?
var resultLast: ListNode?
while tops.count > 0 {
var pickIdx = 0
var val = Int.max
class Solution {
func removePalindromeSub(_ s: String) -> Int {
guard s.count > 0 else { return 0 }
if isPalindrome(s) { return 1 }
return 2
}
private func isPalindrome(_ s: String) -> Bool {
let b = "b".utf8CString[0]