Skip to content

Instantly share code, notes, and snippets.

View T1T4N's full-sized avatar
👽

Robert Armenski T1T4N

👽
View GitHub Profile
@T1T4N
T1T4N / gist:1038bc05d602cec48ff5802709aad7d1
Created April 15, 2024 13:47
Swift flags to disable automatic linking
// https://milen.me/writings/auto-linking-on-ios-and-macos/
// This works
OTHER_SWIFT_FLAGS = $(inherited) -Xfrontend -disable-autolink-framework -Xfrontend TestFramework
// This doesn't work, even though it is referenced here:
// https://github.com/apple/swift/blob/main/include/swift/Option/FrontendOptions.td#L531C47-L531C74
//OTHER_SWIFT_FLAGS = $(inherited) -Xfrontend -disable-autolink-frameworks
@objc public protocol TestProto1 {}
public protocol TestProto2: Hashable {}
public enum Destination: Hashable, Equatable {
// OKAY - Concrete
case test(obj: NSObject)
// Error: any type (not concrete/boxed)
// Type 'AppFeatureDestination' does not conform to protocol 'Equatable'
case test1(obj: NSObject & TestProto1)
@T1T4N
T1T4N / MyAnyHashable.swift
Created April 12, 2024 10:18
A custom simple AnyHashable implementation
protocol HashableBox: Hashable {
func `as`<T : Hashable>(_: T.Type) -> T?
func isEqual(_ other: any HashableBox) -> Bool
}
struct ConcreteHashableBox<Base: Hashable>: HashableBox {
let base: Base
func `as`<T>(_: T.Type) -> T? where T : Hashable {
return base as? T
@T1T4N
T1T4N / LeakMemory.swift
Last active February 16, 2024 10:13
A snippet to leak as much of the available virtual memory in Swift as possible
// Modified from: https://stackoverflow.com/a/45882589
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
var freeMem = Int.max
let reserved = 605696
let chunks = 12000
repeat {
freeMem = os_proc_available_memory()
let toAlloc = freeMem
let mallocSize = toAlloc / chunks
@T1T4N
T1T4N / dynamic_dependencies.sh
Created January 29, 2024 08:42
List all dynamically linked framework dependencies
# Get all dynamically linked framework dependencies
# sort -u is necessary for FAT targets such as iphonesimulator builds
otool -L "/path/to/Example.framework/Example" | \
grep '@rpath' | grep '.framework' | awk '{ print $1 }' | cut -d '/' -f2 | \
xargs -I{} basename "{}" ".framework" | \
sort -u | \
grep -v "Example" | \
while IFS=$'\n' read -r dependency; do
echo "$dependency"
done
@T1T4N
T1T4N / object_hash.js
Created March 28, 2023 10:34
object-hash benchamark
!function(e){var t;"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):("undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.objectHash=e())}(function(){return function r(o,i,u){function s(n,e){if(!i[n]){if(!o[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(a)return a(n,!0);throw new Error("Cannot find module '"+n+"'")}e=i[n]={exports:{}};o[n][0].call(e.exports,function(e){var t=o[n][1][e];return s(t||e)},e,e.exports,r,o,i,u)}return i[n].exports}for(var a="function"==typeof require&&require,e=0;e<u.length;e++)s(u[e]);return s}({1:[function(w,b,m){!function(e,n,s,c,d,h,p,g,y){"use strict";var r=w("crypto");function t(e,t){t=u(e,t);var n;return void 0===(n="passthrough"!==t.algorithm?r.createHash(t.algorithm):new l).write&&(n.write=n.update,n.end=n.update),f(t,n).dispatch(e),n.update||n.end(""),n.digest?n.digest("buffer"===t.encoding?void 0:t.encoding):(e=n.read(),"buffer"!==t.encoding?e.toSt
@T1T4N
T1T4N / exportActionsUnionFromSlice.ts
Last active March 27, 2023 10:05
Use Redux Toolkit's createSlice with useReducer + export a type union of all its actions defined in 'reducers'
// https://stackoverflow.com/a/64582352
export type SliceActions<T> = {
[K in keyof T]: T[K] extends (...args: any[]) => infer A ? A : never;
}[keyof T];
// USAGE - NOTE: This doesn't work with `extraReducers` and the builder syntax
export type MySlice = typeof slice;
export type StateAction = SliceActions<MySlice['actions']>;
export type SliceReducer = Reducer<IState, StateAction>;
@T1T4N
T1T4N / zip.ts
Created March 24, 2023 09:11
Typescript implementation of a zip function
// Source: https://stackoverflow.com/a/70192772/6053417
export function zip<T extends unknown[][]>(
...args: T
): { [K in keyof T]: T[K] extends (infer V)[] ? V : never }[] {
const minLength = Math.min(...args.map((arr) => arr.length));
// @ts-expect-error This is too much for ts
return [...Array(minLength).keys()].map((i) => args.map((arr) => arr[i]));
}
@T1T4N
T1T4N / gist:46e1d3839786f8977be94d46c69233a8
Created February 6, 2023 13:42
macOS: Hide a custom app's dock icon
# https://apple.stackexchange.com/questions/357109/run-applescript-in-background-without-showing-in-app-switcher#comment471468_357109
defaults write '/Applications/AppName.app/Contents/Info.plist' LSUIElement -bool yes
@T1T4N
T1T4N / react-devtools-safari.md
Last active January 31, 2023 14:00
How to get React Devtools working in Safari Developer Tools in 2023

React DevTools In Safari 2023

Credits: Forked from React DevTools in Safari 2022

Introduction

This is a successful experiment in getting React DevTools working in Safari Developer Tools in Safari 16.3 as of January 2023. Potentially, this process can be used with other extensions that extend the developer tools (e.g. Redux, Vue, etc...).

This is only a proof of concept but hopefully this may open the doors for tools that were previously accessible on other browsers to be now available on Safari spurring for a more open web experience (and debugging) for developers.

Requirements

  • macOS 13.2 Ventura