Skip to content

Instantly share code, notes, and snippets.

View JetForMe's full-sized avatar

Rick M JetForMe

View GitHub Profile
@davidsteppenbeck
davidsteppenbeck / Optional+Utilities.swift
Last active July 27, 2021 07:08
An infix operator for collections that returns the wrapped value of the optional only if the collection is not empty.
import Foundation
infix operator ???
extension Optional where Wrapped: Collection {
/// Performs a nil-coalescing operation, returning the wrapped value of an `Optional` instance
/// only if the wrapped value is not empty, otherwise returns a default value.
///
/// - Parameters:
@shaps80
shaps80 / ActivityView.md
Last active December 3, 2022 15:36
A complete SwiftUI UIActivityViewController implementation.

Moved

This is now available in a dedicated package: ActivityView

Alternatively my SwiftUI Backports now includes a more complete implementation of ShareLink that's also more performant.

// Authoer: The SwiftUI Lab
// Full article: https://swiftui-lab.com/scrollview-pull-to-refresh/
import SwiftUI
struct RefreshableScrollView<Content: View>: View {
@State private var previousScrollOffset: CGFloat = 0
@State private var scrollOffset: CGFloat = 0
@State private var frozen: Bool = false
@State private var rotation: Angle = .degrees(0)
@achansonjr
achansonjr / hexdump.swift
Last active January 23, 2023 23:40 — forked from kristopherjohnson/hexdump.swift
Swift: Generate hex dumps for arrays/sequences of bytes.
// hexdump.swift
//
// This file contains library functions for generating hex dumps.
//
// The functions intended for client use are
//
// - `printHexDumpForBytes(_:)`
// - `printHexDumpForStandardInput()`
// - `hexDumpStringForBytes(_:)`
// - `logHexDumpForBytes(_:)`
@Raimondi
Raimondi / Ledger_3_commands.dat
Created June 17, 2017 18:12 — forked from agaviria/Ledger_3_commands.dat
Collection of ledger-cli commands
# comments example for .dat or .ledger files
@smallexample
; This is a single line comment,
# and this,
% and this,
| and this,
* and this.
# If you have a deeply nested tree of accounts,
# it may be convenient to define an alias, for example:
@zappycode
zappycode / NSImageToJpeg.swift
Last active June 12, 2024 02:15
Coverting an NSImage into JPEG Data
func jpegDataFrom(image:NSImage) -> Data {
let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)!
let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])!
return jpegData
}
@jeamland
jeamland / shuttle.swift
Created November 17, 2016 22:51
My stunning adventures in Swift
import Foundation
import IOKit
import IOKit.hid
import Quartz
let ioman = IOHIDManagerCreate(kCFAllocatorDefault,
IOOptionBits(kIOHIDOptionsTypeNone))
let runloop : CFRunLoop = CFRunLoopGetCurrent()
let devices = [
kIOHIDVendorIDKey: 0x0b33,
@hooman
hooman / RationalNumber.swift
Last active January 26, 2021 15:40
Rational numbers in Swift 3.0
// RationalNumber.swift
//
// A basic implementation of Rational numbers in Swift 3.0.
// (c) 2016 Hooman Mehr. Licensed under Apache License v2.0 with Runtime Library Exception
/// A data type to model rational numbers in Swift.
///
/// It always uses fully-reduced representation for simplicity and clarity of comparisons and uses LCM