Skip to content

Instantly share code, notes, and snippets.

View pyxn's full-sized avatar
🎖️

Paul Yu pyxn

🎖️
  • Canada
View GitHub Profile
// --------------------------------------------------------------------------------------
// How To Use Geometry Reader to Access Device Dimensions in SwiftUI
// --------------------------------------------------------------------------------------
// Wrap the view code you wish to measure using the GeometryReader closure.
// Using "device" will provide the most clarity to measuring device view dimensions.
// Access the parent view's dimensions using "device.size.width" or "device.size.height"
// Official Docs: https://developer.apple.com/documentation/swiftui/geometryreader
@pyxn
pyxn / Orientation.swift
Last active April 21, 2020 18:48
Code displays how to switch between Landscape and Portrait views on SwiftUI depending on the current device orientation. This is achieved by attaching "UIDevice.current.orientation" to a State variable and using a .onReceive modifier to detect when the current orientation is changed through the Notification Center Publisher.
//
// Orientation.swift
// Code Template
//
// Created by Pao Yu on 2020-04-18.
// Copyright © 2020 Yu Pao. All rights reserved.
//
import SwiftUI
@pyxn
pyxn / Motion.swift
Last active April 20, 2020 12:22
Parallax motion effect from UIKit repurposed for SwiftUI
import SwiftUI
struct Motion {
let motionEffectGroup: UIMotionEffectGroup = {
let xMotion: UIInterpolatingMotionEffect = {
let min = CGFloat(-30)
let max = CGFloat(30)
let xMotionSetting = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.x", type: .tiltAlongHorizontalAxis)
@pyxn
pyxn / Sound.swift
Created April 20, 2020 12:22
A reusable sound model created for the SwiftUI framework.
import SwiftUI
import AVFoundation
class Sound {
var audioPlayer: AVAudioPlayer?
func soundSetup() {
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient)
@pyxn
pyxn / DeviceSize.swift
Created April 20, 2020 19:29
Custom DeviceSize class template which creates a scale of 21 sizes based on a scale (in this case, the Silver Ratio).
import SwiftUI
class DeviceSize {
var scale: [CGFloat] {
var silverRatioArray: [CGFloat] = [0]
for i in 0 ... 21 {
if i > 1 {
silverArray[i] = silverArray[i - 1] * (1 + sqrt(2))
} else {

// Work-in-progress // script to install jekyll on ZSH.

Installation reference on MacOS Catalina running ZSH shell

Check Ruby and Gem Locations
which ruby
which gem
@pyxn
pyxn / deploy.sh
Last active May 12, 2020 19:53
Shell Script: Git Push Sequence
echo "Initialize $0 script..."
git add .
git commit -m "$1"
git push -u origin master
git log --oneline
echo "$0 successful."
echo "--------------------------------"
# --------------------------------
# Usage on MacOS
@pyxn
pyxn / A001-LED-Blink.ino
Last active June 6, 2020 19:19
Arduino Uno - Makes a single LED blink for 1 second
@pyxn
pyxn / A002-LED-Blink-2.ino
Created June 6, 2020 19:20
Arduino Uno - Makes 2 LEDs blink alternatively for 1 second
@pyxn
pyxn / A003-LED-Array-Blink-Flow.ino
Created June 6, 2020 19:22
Arduino Uno - Makes an array of 10 LEDs blink systematically in a repeating flow motion