Skip to content

Instantly share code, notes, and snippets.

View markmals's full-sized avatar

Mark Malstrom markmals

View GitHub Profile
function LandmarkRow({ landmark }) {
return (
<HStack>
<Image source={landmark.image} resizable />
<Text>{landmark.name}</Text>
<Spacer />
</HStack>
)
}
@markmals
markmals / Publisher+passthrough.swift
Created June 30, 2021 00:07
A passthrough operator for Combine Publishers
extension Publisher {
@discardableResult
func passthrough(_ closure: @escaping (Result<Output, Failure>) -> Void) -> AnyPublisher<Output, Failure> {
map { output in
closure(.success(output))
return output
}
.mapError { error in
closure(.failure(error))
return error
@markmals
markmals / Combine+concurrency.swift
Last active June 24, 2021 09:05
Extensions to Apple's Combine framework to interoperate with Swift 5.5's new concurrency features
import Combine
extension Publisher {
var stream: AsyncThrowingStream<Output> {
AsyncThrowingStream(Output.self) { continuation in
let cancellable = sink { completion in
switch completion {
case .finished: continuation.finish()
case .failure(let error): continuation.finish(throwing: error)
}
@markmals
markmals / Emulator.md
Last active October 10, 2023 16:36
Guides for setting up a Linux computer to play video games in emulators
@markmals
markmals / Wiggle.swift
Last active February 10, 2024 03:44
The iOS Home Screen wiggle animation, in SwiftUI
import SwiftUI
extension View {
func wiggling() -> some View {
modifier(WiggleModifier())
}
}
struct WiggleModifier: ViewModifier {
@State private var isWiggling = false
extension Array {
func combine(_ numberOfElements: Int) -> [[Element]] {
guard numberOfElements > 0 else { return [.init()] }
guard let first = first else { return [] }
return Array(dropFirst())
.combine(numberOfElements - 1)
.map { [first] + $0 } +
Array(dropFirst())
.combine(numberOfElements)
@markmals
markmals / transcode.sh
Last active June 16, 2020 01:08
Transcode video files to Apple-compatible HEVC using ffmpeg
if [[ -d "$1" ]]; then
for file in "$1"/**/*(.); do
ext="${file##*.}"
if [[ $ext == "mkv" ]] || [[ $ext == "mp4" ]] || [[ $ext == "avi" ]]; then
transcode "$file"
fi
done
trash "$1"
import tweepy # pip3 install tweepy
import json
from datetime import datetime, timedelta, timezone
CONSUMER_KEY = "**********"
CONSUMER_SECRET = "**********"
def oauthLogin(consumerKey, consumerSecret):
auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
authURL = auth.get_authorization_url()
@markmals
markmals / String+formattedForPlex.swift
Last active October 14, 2018 06:07
Format a file name of a video to the correct Plex format
extension String {
var formattedForPlex: String {
var newName = self
// Remove all text at the end
let regexEndText = "\\d{3,4}p.+"
if let range = newName.range(of: regexEndText, options: .regularExpression) {
newName.removeSubrange(range)
}
@markmals
markmals / Swift Wish List.md
Last active June 12, 2022 21:10
Features I would like to see from Swift and its core ecosystem

Swift Wish List

Features I would like to see from Swift and its core ecosystem, to make it a robust and ergonomic language for all use cases.

  • ❌ = Unimplemented
  • 📜 = Manifesto
  • ⚾️ = Pitch
  • 💍 = Proposal
  • ⛔️ = Partially Implemented / Awaiting Implementation
  • ⚠️ = In Active Review