Skip to content

Instantly share code, notes, and snippets.

View ryanashcraft's full-sized avatar

Ryan Ashcraft ryanashcraft

View GitHub Profile
@agiletortoise
agiletortoise / example.swift
Created August 24, 2023 18:56
Intent Dependency
// create an object to inject
struct AppIntentDependencyManager {
func hello() {}
// whatever methods you need....
}
// in didFinishLaunching or similar inject your dependency like...
if #available(iOS 16.0, *) {
AppDependencyManager.shared.add(key: "AppIntentDependencyManager", dependency: AppIntentDependencyManager())
@roostr
roostr / Watchdog.swift
Last active March 19, 2024 14:40
A watchdog timer for iOS to detect when the main run loop is stalled
//
// Watchdog.swift
//
// The MIT License (MIT)
// Copyright © 2023 Front Pocket Software LLC
//
// 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:
@akramarev
akramarev / DistributedDataLoader.ts
Last active June 2, 2022 03:47
[Distributed Data Loader] GraphQL data loaders enhanced by distributed cache #AmplitudeEngineeringHandbook #public
import DataLoader from 'dataloader';
import logger from '../../../logger';
export const REDIS_KEY_DELIMITER = '\x1F'; // ASCII unit separator (31 in hex)
export const REDIS_NULL_VALUE = '\x00'; // ASCII NULL (0 in hex), value is set but it's null
export type RedisNullValueType = '\x00';
export type DistributedDataLoaderOptions<K, V> = DataLoader.Options<
K,
@mac-cain13
mac-cain13 / AccessibleHStack.swift
Created July 9, 2020 07:19
SwiftUI - AccessibleHStack
//
// AccessibleHStack.swift
//
// Created by Mathijs Kadijk on 08/07/2020.
//
import SwiftUI
/// HStack that will switch to a VStack when the horizontal size class is compact and the content size category is set to an accessibility size option
struct AccessibleHStack<Content>: View where Content: View {
@Amzd
Amzd / UIKitTabView.swift
Last active March 16, 2024 10:40
UIKitTabView. SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
public struct UIKitTabView: View {
private var viewControllers: [UIHostingController<AnyView>]
private var selectedIndex: Binding<Int>?
@State private var fallbackSelectedIndex: Int = 0
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) {
self.viewControllers = views().map {
let host = UIHostingController(rootView: $0.view)
host.tabBarItem = $0.barItem
import SwiftUI
class MyModel: ObservableObject {
@Published var attempted: Bool = false
@Published var firstname: String = "" {
didSet { updateDismissability() }
}
@Published var lastname: String = "" {
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@alfredringstad
alfredringstad / README.md
Created September 25, 2017 13:26
Forking a single package in a monorepo

Forking a single package in a monorepo

The trend of using monorepos makes a lot of things easier to manage. However, when you want to fork a single package inside a monorepo, you'll have to chose one of two options:

  • Fork the entire monorepo (meaning you get all those extra boilerplate you don't really care about)
  • Manually copying the package files into a new git repo (meaning you'll loose all git history and have a lot of work to do when there's a new version of your base package)

The good news: There's a solution for this! And it's actually built in to git.

git subtree

One of the lesser-known (and vaguely documented) features of git is subtree. It's intended for this purpose, working as a great alternative to the criticized submodules. There are very few resources about using this in practice, so here's a guide for this specific use case.

@rosskevin
rosskevin / relay.js
Last active June 27, 2018 01:07
flow libdef for relay modern 1.2. This is in a _works for me_ state. Someone please export these properly from relay or create a proper flow-typed libdef.
// @flow
declare module 'react-relay' {
declare export type RecordState = 'EXISTENT' | 'NONEXISTENT' | 'UNKNOWN';
declare export type onCompleted = (response: ?Object, errors: ?Array<PayloadError>) => void
declare export type onError = (error: Error) => void
declare export type CommitOptions = {
onCompleted: onCompleted,
@paulirish
paulirish / what-forces-layout.md
Last active April 23, 2024 15:47
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent