Skip to content

Instantly share code, notes, and snippets.

View tkersey's full-sized avatar
:octocat:

Tim Kersey tkersey

:octocat:
View GitHub Profile
@tkersey
tkersey / streamlit_app.py
Created January 31, 2025 17:23 — forked from tvst/streamlit_app.py
Simple way to run heavy computations without slowing down other Streamlit users
import streamlit as st
import concurrent.futures # We'll do computations in separate processes!
import mymodule # This is where you'll do the computation
# Your st calls must go inside this IF block.
if __name__ == '__main__':
st.write("Starting a long computation on another process")
# Pick max number of concurrent processes. Depends on how heavy your computation is, and how
# powerful your machine is.
@tkersey
tkersey / FAQ.md
Created January 28, 2025 14:06 — forked from ngxson/FAQ.md
convert ARM NEON to WASM SIMD prompt

What is your setup?

Just chat.deepseek.com with prompts adapted from this gist.

Does it work in one-shot or I have to prompt it multiple times?

  • For the qX_0 variants, they are actually quite straight-forward so deepseek can come up with a correct result in 1 shot.
  • For the qX_K it's more complicated, I would say most of the time I need to re-prompt it 4 to 8 more times.
  • The most difficult was q6_K, the code never works until I ask it to only optimize one specific part, while leaving the rest intact (so it does not mess up everything)
@tkersey
tkersey / Mutex.swift
Created November 14, 2024 18:38 — forked from swhitty/Mutex.swift
Backports the Swift 6 type Mutex<Value> to all Apple platforms that support OSAllocatedUnfairLock
// Backports the Swift 6 type Mutex<Value> to Swift 5 and all Darwin platforms via OSAllocatedUnfairLock.
// Lightweight version of https://github.com/swhitty/swift-mutex
// Feel free to use any part of this gist.
// Note: ~Copyable are not supported
#if compiler(>=6)
@available(iOS, introduced: 16.0, deprecated: 18.0, message: "use Mutex from Synchronization module included with Swift 6")
@available(macOS, introduced: 13.0, deprecated: 15.0, message: "use Mutex from Synchronization module included with Swift 6")
public struct Mutex<Value>: @unchecked Sendable {
@tkersey
tkersey / CancellingContinuation.swift
Created October 26, 2024 16:44 — forked from NikolaiRuhe/CancellingContinuation.swift
A continuation that resumes automatically when the suspended task is cancelled.
import os.lock
/// `CancellingContinuation` is built on top of `CheckedContinuation` and
/// provides some additional features. It can be used as a drop-in replacement,
/// providing a similar API.
///
/// ## Automatic cancellation
/// When the suspended task is cancelled the continuation is automatically
/// resumed with a `CancellationError`. After that, normally resuming the
/// continuation from client is silently ignored.
@tkersey
tkersey / TMNT Symbols
Created September 11, 2024 03:19 — forked from harlanhaskins/TMNT Symbols
All the iOS 14/macOS 11/tvOS 14/watchOS 7 symbols that are singable to the TMNT theme song
AACustomByteStreamOpen
AAEntryACLBlob
AAEntryXATBlob
AAFieldKeySetGetKeyCount
AAHeaderGetKeyIndex
ABMultiValueGetCount
ABPersonViewController
ADCommonDefinitions
ADErrorAdUnloaded
ADErrorLoadingThrottled
@tkersey
tkersey / FunDay.hs
Created May 12, 2024 06:19 — forked from gelisam/FunDay.hs
a concrete use for FunDay, the right-adjoint of Day
-- A concrete use case for the type which is to '(->)' as 'Day' is to '(,)'.
-- I call it "FunDay", but I don't know what its proper name is. I've been
-- trying to find a use for 'FunDay', and I think I've found a pretty neat one.
{-# LANGUAGE FlexibleContexts, FlexibleInstances, PolyKinds, RankNTypes, TypeSynonymInstances #-}
module Main where
import Test.DocTest
import Control.Monad.Except
import Control.Monad.Reader
@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)
}
}