Skip to content

Instantly share code, notes, and snippets.

View iGranDav's full-sized avatar
🤘
let's make it possible

David Bonnet iGranDav

🤘
let's make it possible
View GitHub Profile
@ncreated
ncreated / GenerateColors.swift
Last active February 20, 2023 16:06
iOS 16.2 colors
import Framer
func testGenerateColors() {
struct CC {
let name: String
let color: UIColor
}
let colors: [CC] = [
CC(name: "systemRed", color: UIColor.systemRed),
@wingovers
wingovers / Autofiller.swift
Last active January 16, 2022 13:45
Guess iOS Device Owner Name
// Ryan Ferrell say(hello) { github.com/wingovers }
class Autofiller {
enum NameComponent {
case givenName
case familyName
case fullNameInCurrentPersonNameComponentsFormatterStyle
}
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@pepasflo
pepasflo / .gitignore
Last active October 22, 2023 12:06
Scripts for encrypting / decrypting secrets (to prevent them from being accidentally checked into git)
secrets/
@DougGregor
DougGregor / dynamic_member_lookup_environment.swift
Created May 2, 2018 16:59
Using Swift 4.2's @dynamicMemberLookup to expose environment variables
import Darwin
@dynamicMemberLookup
struct Environment {
subscript(dynamicMember name: String) -> String? {
get {
guard let value = getenv(name) else { return nil }
return String(validatingUTF8: value)
}
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active July 12, 2024 03:33
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@robbaier
robbaier / gif-optimize.sh
Last active August 3, 2023 21:14
Script to optimize GIFs. Uses Gifsicle to drop frames, increase delay, reduce color depth and optimize
#!/bin/sh
# Script: gif-optimize.sh
# Author: Rob Baier
# Description: Script used to optimize animated GIF files.
# Dependencies: Gifsicle (https://github.com/kohler/gifsicle)
# Environment: Tested on MacOS 10.12. Other *nix environments may require some tweaking.
# Usage: ./gif-optimize.sh input-filename.gif
# Helper function to convert bytes into a human-readable format
@fabiomsr
fabiomsr / ByteArray.kt
Last active April 24, 2024 08:41
ByteArray and String extension to add hexadecimal methods in Kotlin
private val HEX_CHARS = "0123456789ABCDEF".toCharArray()
fun ByteArray.toHex() : String{
val result = StringBuffer()
forEach {
val octet = it.toInt()
val firstIndex = (octet and 0xF0).ushr(4)
val secondIndex = octet and 0x0F
result.append(HEX_CHARS[firstIndex])
@steipete
steipete / ios-xcode-device-support.sh
Last active July 13, 2024 21:09
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
//To prevent the 4-5 seconds lags when you show the keyboard for the first time
import UIKit
extension UIApplication {
func cacheKeyboard()
{
let textField = UITextField()
if let window = windows.last {