Skip to content

Instantly share code, notes, and snippets.

@groue
groue / ObservableState.swift
Last active April 29, 2025 12:19
WithBindable
// Copyright (C) 2024 Gwendal Roué
//
// 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:
//
@darrarski
darrarski / CurrentValueAsyncSequence.swift
Created January 15, 2023 01:18
[swift-concurrency] Async sequence with current value (similar to Combine's CurrentValueSubject).
import Foundation
@dynamicMemberLookup
public actor CurrentValueAsyncSequence<Value>: AsyncSequence where Value: Sendable {
public typealias Element = Value
public init(_ value: Value) {
self.value = value
}
@darrarski
darrarski / EmojiPicker.swift
Last active September 23, 2024 12:20
SwiftUI emoji picker using UIKit on iOS
import SwiftUI
struct EmojiPickerView: UIViewRepresentable {
@Binding var isFirstResponder: Bool
var onPick: (String) -> Void
var onDelete: () -> Void
func makeUIView(context: Context) -> UIViewType {
UIViewType(view: self)
}
@premek
premek / mv.sh
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)
@groue
groue / CancelBag.swift
Last active April 5, 2024 19:12
CancelBag
import Combine
import Foundation
/// A thread-safe store for cancellables which addresses usability pain points
/// with stock Combine apis.
///
/// ## Thread-safe storage of cancellables
///
/// let cancelBag = CancelBag()
/// cancellable.store(in: cancelBag)
@chriseidhof
chriseidhof / collectionview.swift
Last active January 31, 2024 19:00
SwiftUI Flow Layout
//
// ContentView.swift
// DeleteMe
//
// Created by Chris Eidhof on 02.02.21.
//
import SwiftUI
/*
@anandabits
anandabits / Safer SwiftUI Environment.md
Last active November 9, 2023 20:44
Towards a safer SwiftUI environment

Towards a safer SwiftUI environment

Swift UI's @EnvironmentObject is currently prone to runtime errors. If a view uses an environment object of a type that was not injected using environmentObject a fatalError occurs. This document sketches a design that would support compile-time checking of environment object usage. It requires a few language enhancements.

Tuple intersection types

Swift's protocol composition types such as Protocol1 & Protocol2 are a form of intersection types. Other forms of intersection types are possible. For example, Flow has object intersection types. Tuple intersection types for Swift would be very similar to these.

Below, you can see the examples in the Flow documentation converted to Swift's tuples:

@yycking
yycking / JavaScriptCore+fetch.swift
Last active March 19, 2025 13:32
add fetch, console.log and Promise.then/catch to JavaScriptCore on iOS/Mac
import JavaScriptCore
extension JSContext {
subscript(key: String) -> Any {
get {
return self.objectForKeyedSubscript(key) as Any
}
set{
self.setObject(newValue, forKeyedSubscript: key as NSCopying & NSObjectProtocol)
}

Deckset Theme Customization Beta

Download Beta Build (builds expire after 28 days)

Here is an example snippet of the theme configuration commands (place these at the top of your Markdown file):

theme: Work
text: Gill Sans, #F5E5C0, text-scale(0.75), line-height(1.4)
header: Gill Sans UltraBold, text-scale(1.2), line-height(0.9)
const asyncMiddleware = fn =>
(req, res, next) => {
Promise.resolve(fn(req, res, next))
.catch(next);
};