Skip to content

Instantly share code, notes, and snippets.

View tkersey's full-sized avatar
👹

Tim Kersey tkersey

👹
View GitHub Profile
@tkersey
tkersey / links.md
Last active April 24, 2024 22:47
For future reference but maybe not.
@tkersey
tkersey / PollingDataModel.swift
Created April 14, 2024 18:51
An example of using AsyncStream
import Combine
import Foundation
import os
@MainActor public final class PollingDataModel<DataModels: Sendable> {
private let logger = Logger(subsystem: "Polling", category: "PollingDataModel")
private var pollingTask: Task<Void, Never>?
private var currentlyPolling = false
@tkersey
tkersey / Task.swift
Created April 11, 2024 22:16
try await Task.sleep(until: targetDate)
import Foundation
extension Task {
static func sleep(until target: Date) async throws where Success == Never, Failure == Never {
let duration = target.timeIntervalSinceNow
try await Self.sleep(for: .seconds(duration))
}
}
print("Waiting for 1s...")
@tkersey
tkersey / ReducedReplayAsyncStream.swift
Created March 14, 2024 06:27 — forked from ABridoux/ReducedReplayAsyncStream.swift
An AsyncSequence that allows to be consumed several times. Returning the current state as specified in a reduce function
struct ReducedReplayAsyncStream<Element> {
typealias Reduce = (_ partialResult: inout Element, _ nextResult: Element) -> Void
private let storage: _Storage
private var originalStream: AsyncStream<Element>
init(
bufferingPolicy limit: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded,
initialResult: Element,
@tkersey
tkersey / Optional.swift
Last active March 14, 2024 00:41
Missing async functions
extension Optional {
func map<T>(
transform: (Wrapped) async throws -> T
) async rethrows -> T? {
guard case let .some(value) = self else { return nil }
return try await transform(value)
}
}
Remove file from git repository (history)
SOLUTION: This is the shortest way to get rid of the files:
1. check .git/packed-refs - my problem was that I had there a refs/remotes/origin/master line for a remote repository, delete it, otherwise git won't remove those files
2. (optional) git verify-pack -v .git/objects/pack/#{pack-name}.idx | sort -k 3 -n | tail -5 - to check for the largest files
3. (optional) git rev-list --objects --all | grep #{SHA_FROM_#_3} - to check what files those are
@tkersey
tkersey / iOSMemoryDeepDive.md
Created January 23, 2024 18:14
iOS Memory Deep Dive
  • vmmap --summary X.memgraph
  • vmmap X.memgraph | rg "MEMORY REGION NAME"
  • vmmap --verbose X.memgraph | rg "MEMORYREGION"
  • leaks --traceTree 0xSTARTINGMEMORYADDRESS
  • malloc_history X.memgraph --fullStacks 0xSTARTINGMEMORYADRESS
  • Other helpful commands
    • vmmap --pages X.memgraph
    • leaks X.memgraph
  • heap X.memgraph
#!/bin/sh
# Runs SwiftFormat on changed Swift files in the project.
# The re-formatting may not be caught at commit time, though, and so may require a subsequent commit/amending.
# If any command fails, exit immediately with that command's exit status.
# shellcheck disable=SC3040
set -eo pipefail
# Redirect output to stderr.
-- Yoneda --------------------------------------------------------------
newtype Yoneda f a = Yoneda { runYoneda :: forall b. ((a -> b) -> f b) }
instance Functor (Yoneda f) where
fmap f y = Yoneda (\ab -> runYoneda y (ab . f))
toYoneda :: Functor f => f a -> Yoneda f a
toYoneda fa = Yoneda (\f -> fmap f fa)
fromYoneda :: Yoneda f a -> f a
@tkersey
tkersey / gist:1130675
Created August 7, 2011 19:16
Getting a Motorola SBG6580 into “Bridge” mode

found at: http://fascinated.fm/post/2379188731/getting-a-motorola-sbg6580-into-bridge-mode-on

Getting a Motorola SBG6580 into “Bridge” mode on TimeWarner Wideband

  1. Unplug coax cable from Motorola
  2. Hold down the white reset button on the back panel with a pen for 30s.  This resets all settings to factory defaults. The modem will be auto-reconfigured once you plug in the coax cable.
  3. When modem is back on plug in a computer with an Ethernet cable into the modem.
  4. Connect to http://192.168.0.1 and login with “admin” / “motorola”
  5. Now you will make some changes:
 
  • Wireless -> Primary Network -> Disabled