Skip to content

Instantly share code, notes, and snippets.

View TwoDollarsEsq's full-sized avatar
🦊

Artyom Rudakov TwoDollarsEsq

🦊
  • Ukraine, Dnipro
  • 15:35 (UTC +02:00)
View GitHub Profile
//
// CacheAsyncImage.swift
//
// Created by Costantino Pistagna on 08/02/23.
//
import SwiftUI
struct CacheAsyncImage<Content, Content2>: View where Content: View, Content2: View {
private let url: URL?
@mattt
mattt / UIViewControllerPreview.swift
Last active October 7, 2024 06:51
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()
}
@killer-nyasha
killer-nyasha / lsmanual.md
Last active October 11, 2019 14:24
Мануал по LizardScript

LizardScript 🦎

Основная информация

LizardScript - язык программирования:

  • Скриптовый - LizardScript создан для взаимодействия с программами, написанными на C++. Он имеет наибольшее право называться скриптовым.
  • Объектный - с помощью генератора метаданных METAGEN и скрипта make_metadata.py (спасибо Лёхе) из классов C++ извлекаются метаданные членов, и они становятся видимы в контексте LizardScript. Объявлять собственные классы в данный момент невозможно.
  • Динамический - во время выполнения кода LizardScript можно компилировать новые функции с исходным кодом, заданным строковыми переменными.

Программист на LizardScript называется скриптолиз.

FAQ: Зачем ещё один скриптовый язык?

@mattgallagher
mattgallagher / AppDelegate.swift
Last active May 18, 2022 17:42
Animated circle views in SwiftUI and AppKit/CoreAnimation
//
// AppDelegate.swift
// SwiftUITestApp
//
// Created by Matt Gallagher on 4/6/24.
// Copyright © 2019 Matt Gallagher. All rights reserved.
//
import Cocoa
import SwiftUI
@antfarm
antfarm / CRC32.swift
Last active March 29, 2023 10:52
CRC32 checksum generation in a few lines of Swift 5. https://en.wikipedia.org/wiki/Cyclic_redundancy_check#CRC-32_algorithm
class CRC32 {
static var table: [UInt32] = {
(0...255).map { i -> UInt32 in
(0..<8).reduce(UInt32(i), { c, _ in
(c % 2 == 0) ? (c >> 1) : (0xEDB88320 ^ (c >> 1))
})
}
}()
@tjeerdintveen
tjeerdintveen / inspect.swift
Created October 18, 2018 13:24
inspect as an extension on Sequence
extension Sequence {
public func inspect(
_ body: (Element) throws -> Void
) rethrows -> Self {
for element in self {
try body(element)
}
return self
}
}
@bpolania
bpolania / DataExtensions.swift
Last active September 18, 2024 16:49
Swift Extensions for Data, Int, UInt8, UInt16, and UInt32 types
// MIT License
// Copyright (c) 2018 Boris Polania
// 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:
@lattner
lattner / TaskConcurrencyManifesto.md
Last active November 15, 2024 05:45
Swift Concurrency Manifesto
@lattner
lattner / async_swift_proposal.md
Last active October 29, 2024 18:53 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@MaciejGad
MaciejGad / NSImageExtensions.swift
Created March 24, 2017 11:49
NSImage extensions for easy resizing, cropping and saving png images. Version updated for Swift 3. Originally by Raphael Hanneken https://gist.github.com/raphaelhanneken/cb924aa280f4b9dbb480
extension NSImage {
/// Returns the height of the current image.
var height: CGFloat {
return self.size.height
}
/// Returns the width of the current image.
var width: CGFloat {
return self.size.width