Skip to content

Instantly share code, notes, and snippets.

View 1998code's full-sized avatar
👨‍💻
Hello World!

MING 1998code

👨‍💻
Hello World!
View GitHub Profile
@1998code
1998code / demo.swift
Created November 16, 2022 03:48
AppStorage + Sheet + Slider bugs on iOS16
//
// ContentView.swift
// Demo
//
// Created by Ming on 16/11/2022.
//
import SwiftUI
struct ContentView: View {
@1998code
1998code / DynamicIsland.swift
Last active September 17, 2022 10:44
Demo of Dynamic Island
//
// WidgetDemo.swift
// WidgetDemo
//
// Created by Ming on 28/7/2022.
//
import ActivityKit
import WidgetKit
import SwiftUI
@1998code
1998code / scenePhase.swift
Last active September 6, 2022 05:43
Demo of scenePhase (SwiftUI)
//
// ContentView.swift
// ScenePhase
//
// Created by Ming on 6/9/2022.
//
import SwiftUI
struct ContentView: View {
@1998code
1998code / torchFunc.swift
Last active December 14, 2022 01:47
Torch Light Function
import SwiftUI
import AVFoundation
func toggleTorch(on: Bool) {
guard let device = AVCaptureDevice.default(for: .video) else { return }
if device.hasTorch {
do {
try device.lockForConfiguration()
device.torchMode = on ? .on : .off
@1998code
1998code / appIconPicker.swift
Created August 6, 2022 13:09
Pick an app icon
import SwiftUI
struct ContentView: View {
@AppStorage("appIcon") private var appIcon: String = ""
@State var appIcons = ["AppIcon", "AppIcon 2"]
var body: some View {
Picker(selection: $appIcon, label: Text("App Icon Picker")) {
ForEach(appIcons, id: \.self) { icon in
Text(icon).tag(icon)
}
@1998code
1998code / PizzaDeliveryAttributes.swift
Created July 29, 2022 06:45
Pizza Delivery Attributes Sample
struct PizzaDeliveryAttributes: ActivityAttributes {
public typealias PizzaDeliveryStatus = ContentState
public struct ContentState: Codable, Hashable {
var driverName: String
var estimatedDeliveryTime: Date
}
var numberOfPizzas: Int
var totalAmount: String
@1998code
1998code / PizzaWidget.swift
Created July 29, 2022 05:43
Pizza Widget Sample
import ActivityKit
import WidgetKit
import SwiftUI
@main
struct Widgets: WidgetBundle {
var body: some Widget {
PizzaDeliveryActivityWidget()
}
}
@1998code
1998code / pizzaFunction.swift
Created July 29, 2022 05:25
Pizza Order Function (iOS 16 Live Activities)
func startDeliveryPizza() {
let pizzaDeliveryAttributes = PizzaDeliveryAttributes(numberOfPizzas: 1, totalAmount:"$99")
let initialContentState = PizzaDeliveryAttributes.PizzaDeliveryStatus(driverName: "TIM 👨🏻‍🍳", estimatedDeliveryTime: Date().addingTimeInterval(15 * 60))
do {
let deliveryActivity = try Activity<PizzaDeliveryAttributes>.request(
attributes: pizzaDeliveryAttributes,
contentState: initialContentState,
pushType: nil)
@1998code
1998code / getDalle2.js
Created July 10, 2022 01:57
Function of getDalle2
function getDalle2() {
setError(false);
setLoading(true);
fetch(`/api/dalle2?k=${token}&q=${query}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => res.json())
@1998code
1998code / dalle2.js
Created July 10, 2022 01:56
DALL-E 2 API
import { Dalle } from "dalle-node"
export default async function handler(req, res) {
const dalle = new Dalle(req.query.k);
const generations = await dalle.generate(req.query.q);
res.status(200).json({ result: generations })
}