Skip to content

Instantly share code, notes, and snippets.

View GrfxGuru's full-sized avatar

Peter Witham GrfxGuru

View GitHub Profile
@GrfxGuru
GrfxGuru / swift_optional
Last active August 29, 2015 14:02
Simple Swift optional example both long and short version.
let numberOfWheels = [“car”: 4, “bike”: 1, "legs" : 0]
let wheelCount: Int? = numberOfWheels[“unicycle”]
// Now to unwrap wheelCount, if wheelCount is nil then
// the if block is never executed
// Long way
if wheelCount == nil {
println(“unicycle wasn’t found”)
@GrfxGuru
GrfxGuru / gist:455c3bd8935227996da8597e19d50098
Created January 8, 2017 04:30
Set location of macOS Screenshots
defaults write com.apple.screencapture location ~/ <some location>
killall SystemUIServer
@GrfxGuru
GrfxGuru / code.swift
Created March 11, 2017 05:26
Swift Convenience Initializers
class Human {
var arms: Int
var legs: Int
var ears: Int
init(arms: Int, legs: Int, ears: Int) {
self.arms = arms
self.legs = legs
self.ears = ears
}
@GrfxGuru
GrfxGuru / code.swift
Created March 11, 2017 05:41
Example of using Guard to exit early with readable code
func nameOnTheList(name: String) {
guard name == "Peter" else {
print("Not getting in!")
return
}
print("Come on in!")
}
nameOnTheList(name: "Peter")
nameOnTheList(name: "Ken")
@GrfxGuru
GrfxGuru / SceneAutoLoader.cs
Created January 2, 2019 06:50
Unity 3D Script to specify which scene is loaded when playing in the editor
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
/// <summary>
/// Scene auto loader.
/// </summary>
/// <description>
/// This class adds a File > Scene Autoload menu containing options to select
/// a "master scene" enable it to be auto-loaded when the user presses play
@GrfxGuru
GrfxGuru / bootstrap_mac.sh
Last active October 23, 2022 17:05
My bootstrap for setting up a new macOS machine
#!/usr/bin/env bash
#
# Bootstrap script for setting up a macOS machine
#
#
echo "Remember to install Xcode from the Store first"
echo "Starting bootstrapping"
@GrfxGuru
GrfxGuru / rename_me.gitignore
Created February 6, 2022 21:01
.gitignore for Xcode, Swift, SwiftUI projects
# Created by https://www.toptal.com/developers/gitignore/api/swift,swiftpackagemanager,xcode,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=swift,swiftpackagemanager,xcode,macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride