Skip to content

Instantly share code, notes, and snippets.

@IanKeen
IanKeen / UserDefaultsKey.swift
Last active December 24, 2024 23:12
Simple type safe wrapper around UserDefaults
struct UserDefaultsKey<T: Codable> {
var name: String
var `default`: T
}
extension UserDefaults {
func get<T>(_ key: UserDefaultsKey<T>) -> T {
guard
let data = data(forKey: key.name),
let box = try? JSONDecoder().decode(Box<T>.self, from: data)
//
// StreamLogoMarchingAnts.swift
// CustomShapeOutlines
//
// Created by from getstream.io on 12.2.2022.
//
import SwiftUI
struct StreamLogoMarchingAnts: View {
@kkrypt0nn
kkrypt0nn / ansi-colors-discord.md
Last active August 26, 2025 13:44
A guide to ANSI on Discord

A guide to ANSI on Discord

Discord is now slowly rolling out the ability to send colored messages within code blocks. It uses the ANSI color codes, so if you've tried to print colored text in your terminal or console with Python or other languages then it will be easy for you.

Quick Explanation

To be able to send a colored text, you need to use the ansi language for your code block and provide a prefix of this format before writing your text:

\u001b[{format};{color}m
@dmr121
dmr121 / PomodoroPicker.swift
Last active June 17, 2025 07:38
SwiftUI - Snapping horizontal scrolling pomodoro picker
//
// PomodoroPicker.swift
// pomodoro
//
// Created by David Rozmajzl on 1/1/22.
//
import SwiftUI
struct PomodoroPicker<Content, Item: Hashable>: View where Content: View {
@BrentMifsud
BrentMifsud / PreviewDevice+Devices.swift
Last active October 31, 2022 18:50
Extension on PreviewDevice that includes all available devices
import SwiftUI
/// Static properties for all preview devices.
///
/// Usage:
///
/// ```swift
/// struct TestView_Previews: PreviewProvider {
/// static var previews: some View {
/// Group {
@facelessuser
facelessuser / okhsl.py
Last active August 4, 2025 16:15
Okhsl and Okhsv
"""
Okhsl class.
Translation to/from Oklab is licenced under MIT by the original author, all
other code also licensed under MIT: Copyright (c) 2021 Isaac Muse.
---- Oklab license ----
Copyright (c) 2021 Björn Ottosson
// Author: SwiftUI-Lab (www.swiftui-lab.com)
// Description: This code is part of the "Advanced SwiftUI Animations - Part 5"
// Article: https://swiftui-lab.com/swiftui-animations-part5/
import SwiftUI
struct ContentView: View {
var body: some View {
DigitalRain()
}
else if type == NSFetchedResultsChangeType.move {
// A hackish way to ensure PIN icon is updated.
if let newIndexPath = newIndexPath, let indexPath = indexPath {
if let plainNote = nsPlainNoteProvider.getNSPlainNote(newIndexPath), let noteCell = collectionView.cellForItem(at: indexPath) as? NoteCell {
noteCell.update(
plainNote,
selected: false,
animate: false
)

Breaking Changes of discord.py 2.0

These are the breaking changes of discord.py version 2.0.

"Breaking change" includes:

  • [R]emoval: a feature is removed.
  • [N]ame changes: a feature is renamed.
  • [B]ehavior: something does not behave the way they did in 1.x.
  • [T]yping: types of arguments, attributes or return values changes in an incompatible way. (e.g. None disallowed for argument)
  • [S]yntax: a syntax previously allowed for an operation is no longer allowed. (e.g. positional only arguments, new required arguments)
@kkebo
kkebo / ShazamKit.swift
Last active June 21, 2022 17:38
ShazamKit on Swift Playgrounds 3.4 on iPadOS 15
import Foundation
import AVFoundation
Bundle(path: "/System/Library/Frameworks/ShazamKit.framework")!.load()
class SHSession {
static let rawType = NSClassFromString("SHSession") as! NSObject.Type
let rawValue: NSObject
var delegate: SHSessionDelegate? {