Skip to content

Instantly share code, notes, and snippets.

View matthewspear's full-sized avatar
🔨
Always Be Learning

Matt Spear matthewspear

🔨
Always Be Learning
View GitHub Profile
@matthewspear
matthewspear / common_commands.sh
Last active May 26, 2020 01:41
Find out which commands you use most on the command-line
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 April 27, 2020 13:32
Slightly hacky script to toggle macOS greyscale mode on / off.
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 June 5, 2019 16:36
A TableView-Style List in SwiftUI
import SwiftUI
import PlaygroundSupport
struct Contact: Identifiable {
// important for each to be unique
var id = UUID()
var name: String
}
@matthewspear
matthewspear / selfcontrol-aliases
Last active July 29, 2016 12:57
SelfControl Terminal Shortcuts
# 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
### 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 / SimpleArraySum.swift
Last active May 5, 2016 17:59
Commandline Swift Script - use 'xcrun -sdk macosx swiftc 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 / Person.swift
Created April 28, 2016 18:16
Example using a lazy variable as a first class citizen + date formatters!
import UIKit
class Person
{
let name: String
let birthday: NSDate
lazy var age: Double = self.calculateAge()
init(name: String, birthday: NSDate)
{
@matthewspear
matthewspear / fizzbuzz.py
Last active February 15, 2016 22:07
Functional FizzBuzz Generator in Python
# 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 February 1, 2016 01:32
Calendar name conversion over all events (Manchester CS timetable)
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 January 20, 2016 01:22
Swift 2.0 FizzBuzz
//: 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)
{