Skip to content

Instantly share code, notes, and snippets.

Avatar
🍎
soon → the fruit company

Andrew Zheng aheze

🍎
soon → the fruit company
View GitHub Profile
@aheze
aheze / Find-Objects-Dogs.text
Last active December 5, 2022 16:55
Find supports recognizing these dogs.
View Find-Objects-Dogs.text
Chihuahua
Japanese spaniel
Maltese dog, Maltese terrier, Maltese
Pekinese, Pekingese, Peke
Shih-Tzu
Blenheim spaniel
papillon
toy terrier
Rhodesian ridgeback
Afghan hound, Afghan
View SegmentedProgress.swift
struct ContentView: View {
var numberOfSegments = 4
@State var currentSegment: Int?
@State var autoIncrementing = false
var period = CGFloat(0.8)
var body: some View {
VStack {
Text("Progress")
.bold()
View VisualEffectView.swift
/// Use UIKit blurs in SwiftUI.
struct VisualEffectView: UIViewRepresentable {
/// The blur's style.
public var style: UIBlurEffect.Style
/// Use UIKit blurs in SwiftUI.
public init(_ style: UIBlurEffect.Style) {
self.style = style
}
View PressedButtonStyle.swift
struct PressedButtonStyle: ButtonStyle {
@Binding var isPressed: Bool
func makeBody(configuration: Configuration) -> some View {
var animation: Animation?
/// only change when it's different
if isPressed != configuration.isPressed {
if configuration.isPressed {
animation = .spring(
View ScalingButtonStyle.swift
struct ScalingButtonStyle: ButtonStyle {
var scale = CGFloat(0.95)
func makeBody(configuration: Configuration) -> some View {
let animation: Animation? = {
if configuration.isPressed {
/// pressing down
return .spring(
response: 0.19,
dampingFraction: 0.45,
@aheze
aheze / Tip.swift
Created October 6, 2022 01:19
Tip using Popovers
View Tip.swift
//
// PhotosVC+Tips.swift
// Find-3
//
// Created by A. Zheng (github.com/aheze) on 10/4/22.
// Copyright © 2022 A. Zheng. All rights reserved.
//
import Popovers
import SwiftUI
@aheze
aheze / Pulse.swift
Created October 3, 2022 02:03
SwiftUI pulse animation
View Pulse.swift
struct ContentView: View {
static let fadeInDuration = CGFloat(1.1)
static let pulseDuration = CGFloat(1.6)
static let fadeOutDuration = CGFloat(0.3)
static let interval = CGFloat(1.6)
@State var isAnimating = false
@State var timer = Timer.publish(every: interval, on: .main, in: .common).autoconnect()
@State var circlesIDs = [UUID()]
@aheze
aheze / starcounter
Last active September 12, 2022 18:50
Count how many stars you have on GitHub!
View starcounter
# Paste this into your terminal:
curl https://gist.githubusercontent.com/aheze/8e7910c3b48e383bae07d27d4fb9cf57/raw/e5242c41703572936e93fee691e37d23903c9824/starcounter.js -sSL | node - aheze -t 10
View starcounter.js
var https = require('https'),
user = process.argv[2],
opts = parseOpts(process.argv.slice(3))
request('/users/' + user, function (res) {
if (!res.public_repos) {
console.log(res.message)
return
}
var pages = Math.ceil(res.public_repos / 100),
View SizeReader.swift
public extension View {
/**
Read a view's size. The closure is called whenever the size itself changes, or the transaction changes (in the event of a screen rotation.)
From https://stackoverflow.com/a/66822461/14351818
*/
func sizeReader(size: @escaping (CGSize) -> Void) -> some View {
return background(
GeometryReader { geometry in
Color.clear
.preference(key: ContentSizeReaderPreferenceKey.self, value: geometry.size)