Skip to content

Instantly share code, notes, and snippets.

View maxxfrazer's full-sized avatar
🥽

Max Cobb maxxfrazer

🥽
View GitHub Profile
@maxxfrazer
maxxfrazer / xcframework_to_vision.sh
Created December 7, 2023 15:01
Script to process .xcframework files and create new versions with specific configurations.
#!/bin/bash
# Script to process .xcframework files and create new versions with specific configurations
# Usage: ./script_name.sh path_to_xcframeworks
set -e # Exit immediately if a command exits with a non-zero status
all_frameworks_path="$1" # The first argument is the path to the xcframeworks
# Change directory to the specified frameworks path
pushd "$all_frameworks_path" > /dev/null
@maxxfrazer
maxxfrazer / pdf_compressor_ghostscript.py
Last active December 4, 2023 17:00
Python Script for Compressing PDFs using Ghostscript: This script enables users to easily compress PDF files by utilizing the Ghostscript tool. It offers different quality settings for compression, catering to various needs for file size reduction. The script includes detailed documentation and instructions for installing Ghostscript on differen…
"""
PDF Compressor using Ghostscript
This script allows the user to compress PDF files using Ghostscript. It provides
options to set the compression quality.
Requirements:
- Python 3.x
- Ghostscript installed on the system
@maxxfrazer
maxxfrazer / CustomBox+Collisions.swift
Created August 7, 2019 20:29
Collisions example for an Entity in RealityKit
extension CustomBox {
func addCollisions() {
guard let scene = self.scene else {
return
}
// Add the subscription for when this cube
collisionSubs.append(scene.subscribe(to: CollisionEvents.Began.self, on: self) { event in
// Get both CustomBox entities, if either entityA or entityB isn't a CustomBox
// then return becasue this is not the collision we're looking for
guard let boxA = event.entityA as? CustomBox, let boxB = event.entityB as? CustomBox else {
@maxxfrazer
maxxfrazer / CustomBox.swift
Created August 7, 2019 20:24
Example of a custom Entity for RealityKit
class CustomBox: Entity, HasModel, HasCollision, HasAnchoring {
/// Used to keeping a reference of any subscriptions involving this entity
var entitySubs: [Cancellable] = []
required init(color: UIColor) {
super.init()
// Shape of this entity for any collisions including gestures
self.components[CollisionComponent] = CollisionComponent(
@maxxfrazer
maxxfrazer / ViewController+Occlusions.swift
Last active March 15, 2022 16:15
Simple example of setting up vertical and horizontal detected planes to occlude objects in SceneKit
import ARKit
extension ViewController {
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let planeAnchor = anchor as? ARPlaneAnchor, let geom = ARSCNPlaneGeometry(device: MTLCreateSystemDefaultDevice()!) else {
return
}
geom.update(from: planeAnchor.geometry)
geom.firstMaterial?.colorBufferWriteMask = .alpha
node.geometry = geom
@maxxfrazer
maxxfrazer / nextPow2.swift
Last active March 27, 2022 16:13
Next power of 2 (Swift)
import Foundation
// Little trick for quickly getting the next power of 2 in swift
// Easier to understand, but slightly less optimised
func nextPow2(of val: Int) => Int {
return 1 << String(num - 1, radix: 2).count
}
// Found that the (marginally) faster way is to use bitwise OR
func optimised_nextPow2(of val: Int) => Int {
@maxxfrazer
maxxfrazer / round.go
Last active August 29, 2015 14:14
minimal round function for golang
package main
import (
"log"
"math"
)
func Round(val float64) float64 {
return math.Floor(val + 0.5)