Skip to content

Instantly share code, notes, and snippets.

Avatar
🔨
Always Be Learning

Matthew Spear Matthewspear

🔨
Always Be Learning
View GitHub Profile
@Matthewspear
Matthewspear / common_commands.sh
Last active May 26, 2020
Find out which commands you use most on the command-line
View common_commands.sh
history > history.txt
awk '{print $1}' ../history.txt > commands.txt
cat commands.txt | sort | uniq -c | sort -r > sorted_commands.txt
@Matthewspear
Matthewspear / ToggleGreyscale.scpt
Created Apr 27, 2020
Slightly hacky script to toggle macOS greyscale mode on / off.
View ToggleGreyscale.scpt
tell application "System Preferences"
set current pane to pane id "com.apple.preference.universalaccess"
delay 1
tell application "System Events" to tell process "System Preferences" to tell window "Accessibility"
select row 5 of table 1 of scroll area 1
tell tab group 1 of group 1
click radio button "Colour Filters"
click pop up button 1
click menu item "Greyscale" of menu 1 of pop up button 1
click checkbox "Enable Colour Filters"
@Matthewspear
Matthewspear / Contents.swift
Created Jun 5, 2019
A TableView-Style List in SwiftUI
View Contents.swift
import SwiftUI
import PlaygroundSupport
struct Contact: Identifiable {
// important for each to be unique
var id = UUID()
var name: String
}
View gist:f3526218077bbe0013f2e0ab009831bd
### Keybase proof
I hereby claim:
* I am matthewspear on github.
* I am matthewspear (https://keybase.io/matthewspear) on keybase.
* I have a public key whose fingerprint is 7430 C437 5A47 3405 AB10 D169 F8D6 8498 7F65 3D4E
To claim this, I am signing this object:
@Matthewspear
Matthewspear / Person.swift
Created Apr 28, 2016
Example using a lazy variable as a first class citizen + date formatters!
View Person.swift
import UIKit
class Person
{
let name: String
let birthday: NSDate
lazy var age: Double = self.calculateAge()
init(name: String, birthday: NSDate)
{
@Matthewspear
Matthewspear / SimpleArraySum.swift
Last active May 5, 2016
Commandline Swift Script - use 'xcrun -sdk macosx swiftc SimpleArraySum.swift'
View SimpleArraySum.swift
import Foundation
// Setup Standard Output, Error
let stderr = NSFileHandle.fileHandleWithStandardError()
let stdout = NSFileHandle.fileHandleWithStandardOutput()
func writeToStd(handle: NSFileHandle, _ str: String)
{
if let data = str.dataUsingEncoding(NSUTF8StringEncoding)
{
@Matthewspear
Matthewspear / selfcontrol-aliases
Last active Jul 29, 2016
SelfControl Terminal Shortcuts
View selfcontrol-aliases
# Add these lines to ~/.bash_profile or ~/.zshrc:
# SelfControl
alias sc-read="defaults read org.eyebeam.SelfControl"
alias sc-run="sudo /Applications/SelfControl.app/Contents/MacOS/org.eyebeam.SelfControl $(id -u $(whoami)) --install"
alias sc-check="sudo /Library/PrivilegedHelperTools/org.eyebeam.SelfControl $(id -u $(whoami)) --checkup"
sc-set()
{
if [ "$1" = "" ]; then
@Matthewspear
Matthewspear / fizzbuzz.py
Last active Feb 15, 2016
Functional FizzBuzz Generator in Python
View fizzbuzz.py
# Functional FizzBuzz Generator in Python
def fizz_buzz(num):
if num % 3 == 0 and num % 5 == 0:
return 'FizzBuzz'
elif num % 3 == 0:
return 'Fizz'
elif num % 5 == 0:
return 'Buzz'
else:
return str(num)
@Matthewspear
Matthewspear / calendarConversion.scpt
Created Feb 1, 2016
Calendar name conversion over all events (Manchester CS timetable)
View calendarConversion.scpt
tell application "Calendar"
tell calendar "Timetable"
--reload calendars
set theEvents to {}
set AllEvents to events
repeat with anEvent in AllEvents
@Matthewspear
Matthewspear / Contents.swift
Last active Jan 20, 2016
Swift 2.0 FizzBuzz
View Contents.swift
//: Playground - noun: a place where people can play
func fizzBuzz(n: Int) -> String
{
let divThree = (n % 3 == 0)
let divFive = (n % 5 == 0)
var numberName = ""
if (divThree && divFive)
{