Skip to content

Instantly share code, notes, and snippets.

View bogren's full-sized avatar
🎧
-

Emil Bogren bogren

🎧
-
View GitHub Profile
@JRR-OSU
JRR-OSU / CrossFadeAndFlipExample.swift
Last active August 11, 2023 08:27
SwiftUI Crossfade and Flip Shader Example
import SwiftUI
struct DemoView: View {
@State var effectValue: Double
let end = 2.75
init() {
self._effectValue = State(initialValue: end)
@dkun7944
dkun7944 / ContentView.swift
Created July 31, 2023 03:36
AirDrop iOS 17 Swift.Shader Animation
//
// ContentView.swift
// Airdrop Demo
//
// Created by Daniel Kuntz on 7/30/23.
//
import SwiftUI
struct ContentView: View {

Delete All your Tweets

This script it based on @chrisalbon's original script, but instead of fetching the users timeline via the Twitter API it uses the archive of the users data to workaround the 3200 tweet limitation.

Setup

  1. Create a virtualenv
  2. Run pip install -r requirements.txt
  3. Create a Twitter developer app.
@kieranb662
kieranb662 / StickyDrag.swift
Created November 2, 2020 03:22
Sticky drag modifier. This modifier adds a drag gesture to the view it modifies. This drag gesture behaves a lot like a rubber band be pulled to its breaking point.
// Swift toolchain version 5.0
// Running macOS version 10.15
// Created on 11/1/20.
//
// Author: Kieran Brown
//
import SwiftUI
import UIKit
@Jeehut
Jeehut / SafeLocalizedStringKey.swift
Created July 19, 2020 17:00
Exploring safer localization workflows in SwiftUI ...
// Copyright © 2020 Flinesoft. All rights reserved.
import Foundation
import SwiftUI
public struct SafeLocalizedStringKey :
ExpressibleByStringLiteral,
ExpressibleByStringInterpolation,
ExpressibleByExtendedGraphemeClusterLiteral,
ExpressibleByUnicodeScalarLiteral,
//
// Config.swift
// Analytics
//
public protocol AnalyticsConfig {
static var analyticsKey: String { get }
static var appVersion: String { get }
}
@JohnSundell
JohnSundell / TestingMemoryManagement.swift
Created January 25, 2017 11:15
Sample on how you can easily test your memory management in Swift
class Cache<T> {
private lazy var objects = [String : T]()
func object(forKey key: String) -> T? {
return objects[key]
}
func addObject(_ object: T, forKey key: String) {
objects[key] = object
}
@michaelevensen
michaelevensen / PagingCollectionViewController.swift
Last active April 10, 2024 08:46
An example of perfectly paging horizontal UICollectionViewController with overflowing cells. Works great with Storyboard — no need to set any specific attributes, just add this Class to the Controller and set your desired size for the cells like you would normally.
import UIKit
private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController {
/* Custom scrollView for paging */
let pagingScrollView = UIScrollView()
/* Return item size */
@andymatuschak
andymatuschak / States-v3.md
Last active June 12, 2024 04:17
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

// See: https://devforums.apple.com/message/1000934#1000934
import Foundation
// Logic
operator prefix ¬ {}
@prefix func ¬ (value: Bool) -> Bool {
return !value
}