Skip to content

Instantly share code, notes, and snippets.

@CharlyWargnier
CharlyWargnier / GTP3_script_for_sheets.txt
Created January 15, 2023 15:00
A script to integrate GTP3 in Google Sheets
const OPENAI_API_KEY = ""; // <- PASTE YOUR SECRET KEY HERE
const OPENAI_API_URL = "https://api.openai.com/v1/completions";
/**
* Submits a prompt to GPT-3 and returns the completion
*
* @param {string} prompt Prompt to submit to GPT-3
* @param {float} temperature Model temperature (0-1)
* @param {string} model Model name (e.g. text-davinci-002)
@minsOne
minsOne / Runtime.swift
Last active February 14, 2023 09:30 — forked from codelynx/Runtime.swift
[Swift] To retrieve classes at runtime which conforms to a protocol or to retrieve subclasses of a given class
//
// Runtime.swift
// Swift Runtime [Swift 4]
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@DougGregor
DougGregor / macros.md
Last active October 24, 2023 16:42
A possible vision for macros in Swift

A Possible Vision for Macros in Swift

As Swift evolves, it gains new language features and capabilities. There are different categories of features: some fill in gaps, taking existing syntax that is not permitted and giving it a semantics that fit well with the existing language, with features like conditional conformance or allowing existential values for protocols with Self or associated type requirements. Others introduce new capabilities or paradigms to the language, such as the addition of concurrency or comprehensive reflection.

There is another large category of language features that provide syntactic sugar to eliminate common boilerplate, taking something that can be written out in long-form and making it more concise. Such features don't technically add any expressive power to the language, because you can always write the long-form version, but their effect can be transformational if it enables use cases that would otherwise have been unwieldy. The synthesis of Codable conformances, for ex

@swiftui-lab
swiftui-lab / grid-trainer.swift
Last active October 21, 2024 15:24
A grid trainer for Grid views
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: this learning tool is designed to showcase the different
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the
// blog article: https://swiftui-lab.com/eager-grids
//
import SwiftUI
import UniformTypeIdentifiers
// The root view of the application
struct ContentView: View {
//
// SwiftUIViews.swift
// CombineApp
//
// Created by Abdullah Kardas on 10.07.2022.
//
import SwiftUI
struct SwiftUIViews: View {
@Sherlouk
Sherlouk / AccessibilityPreview.swift
Created June 8, 2022 20:05
SwiftUI view for adding accessibility previews. Proof of concept.
import SwiftUI
import UIKit
// from https://github.com/cashapp/AccessibilitySnapshot
import AccessibilitySnapshotCore
struct AccessibilityPreview<Content: View>: View {
let content: Content
var body: some View {
// Type-safe State Machine with Phantom Type May 2022 @AtarayoSD
import Foundation
protocol State {}
// Transitions
protocol TransferableToB {}
protocol TransferableToC {}
protocol TransferableToD {}
@YusukeHosonuma
YusukeHosonuma / The introduction to SwiftUI.md
Last active March 22, 2025 09:20
あなたが求めていた SwiftUI 入門(未完結)

昔に書いていた未完結の記事ですが、それでも宜しければどうぞです🙏

あなたが求めていた SwiftUI 入門(未完結)

あなたは今年こそ SwiftUI を学ぶ必要があると感じている。

それは今年の WWDC20 で発表された Widget と呼ばれる機能が SwiftUI でしか作成できないことを聞いたからかもしれないし、SwiftUI 100% でマルチプラットフォームのアプリを作成できるようになったからかもしれないし、あるいはいつまでも UIKit に依存しているのはリスクだと感じ取ったのかもしれない。

学習の上で一番難しい部分は、SwiftUI で考えるということだ。従来の命令的でステートフルなプログラミングから離れて、宣言的でステートレスに考えるように脳を強制しなくてはならない。すでに日本でも SwiftUI の書籍はいくつか発売されているが、その多くは使い方に関することが中心で、SwiftUI が**どのように動くのか(How it works)**についての解説は不足しているものが多いように感じる。

@YusukeHosonuma
YusukeHosonuma / README.md
Last active June 24, 2023 14:44
[Swift] Class diagram of Swift Concurrency (async_await)
extension Task where Failure == Error {
// Start a new Task with a timeout. If the timeout expires before the operation is
// completed then the task is cancelled and an error is thrown.
init(priority: TaskPriority? = nil, timeout: TimeInterval, operation: @escaping @Sendable () async throws -> Success) {
self = Task(priority: priority) {
try await withThrowingTaskGroup(of: Success.self) { group -> Success in
group.addTask(operation: operation)
group.addTask {
try await _Concurrency.Task.sleep(nanoseconds: UInt64(timeout * 1_000_000_000))