Skip to content

Instantly share code, notes, and snippets.

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

MING 1998code

👨‍💻
Hello World!
View GitHub Profile
//
// ARCView.swift
// ARMotion
//
// Created on 9/2/20.
//
import SwiftUI
import Lottie
//
// ViewController.swift
// ARMotion
//
// Created on 9/2/20.
//
// Give Credit to Sarang Borude @sarangborude
import UIKit
import SceneKit
SignInWithAppleButton(
// Request User FullName and Email
onRequest: { request in
// You can change them if needed.
request.requestedScopes = [.fullName, .email]
},
// Once user complete, get result
onCompletion: { result in
// Switch result
switch result {
@1998code
1998code / demoButton.swift
Last active December 18, 2021 12:24
SwiftUI 3 save contacts button
// iOS 15 or above
Button("+ Add to Contacts") {
// Create a mutable object to add to the contact.
// Mutable object means an object state that can be modified after created.
let contact = CNMutableContact()
// Name
contact.givenName = "Ming"
// Phone No.
contact.phoneNumbers = [CNLabeledValue(label: CNLabelPhoneNumberiPhone, value: CNPhoneNumber(stringValue: "12345678"))]
@1998code
1998code / EmailDemo.html
Created April 15, 2022 05:25
Email Demo that handle dark mode for Apple Mail Client
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Dark Mode Test</title>
<meta name="color-scheme" content="light dark">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
@1998code
1998code / pcs.css
Created April 15, 2022 05:39
@media (prefers-color-scheme: dark)
@media (prefers-color-scheme: dark) {
body {
background-color: #000;
color: white;
}
}
@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 })
}
@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 / 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 / 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()
}
}