Skip to content

Instantly share code, notes, and snippets.

View WillBishop's full-sized avatar

Will Bishop WillBishop

View GitHub Profile
@WillBishop
WillBishop / convert.sh
Created July 7, 2024 08:36
Convert all images from png/jpeg to heif
# Convert .png and .jpeg files to .heif format, ensuring "xcassets" is in the path
# Depending on what folder your icons are in, you may wish to append ' -not -path "*/Icons/*"' to that find command so you don't convert all your icon assets.
find . -path "*xcassets*" \( -name "*.png" -o -name "*.jpeg" \) | while read -r file; do
# Get the filename without the extension
filename="${file%.*}"
# Run the magick command to convert the file to .heif
/opt/homebrew/bin/magick "$file" "$filename.heif"
rm "$file"
@WillBishop
WillBishop / LiveActivityImage.swift
Created September 16, 2022 02:59
Using Images in Live Activities without exceeding 4kb limit
struct LiveActivityAttributes: ActivityAttributes {
typealias ContentState = LiveActivityState
struct LiveActivityState: Codable, Hashable {
var activityScore: Int
}
var activityName: String
var _image: UIImage?
@WillBishop
WillBishop / ImageSwap.swift
Created August 24, 2022 01:14
Change UIAction state without dismissing menu in iOS 16
//Bit of a crude example but it all works
var menu: UIMenu!
var selected = false
let toggleSelectionHandler: (UIAction) -> Void = { action in
selected.toggle()
// Actions are immutable once they're a child of a UIMenu, so we must create a copy before we modify anything
let replacementAction = action.copy() as! UIAction
if selected {
@WillBishop
WillBishop / stock.py
Created May 10, 2020 12:13
Get stock from Apple with a postcode and part number
import requests
import json
import datetime
import time
import sys
import os
params = (
('parts.0', '%s/A' % sys.argv[1]),
('location', sys.argv[2]),
static var username: String{
return keychain.get("username")!
}
static var password: String{
return keychain.get("password")!
}
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(.useCredential, URLCredential(user: NetworkManager.username, password: NetworkManager.password, persistence: .synchronizable))
import re #This is regex, it's kind of advanced for a beginner project to be honest
from string import punctuation #Punctuation is an array of all English puncutation marks, we use this to not translate anything that is punctuation
def convert_to_pyglatin(user_input): #Defining a function which takens one input parameter
words = re.findall(r"[\w']+|[.,!?;]", user_input) #regexr.com/4cim0 <- Look at this for an explanation
final_string = "" #I create an empty string where we add our words to in our loop
for word in words: #This is a for-loop, it'll go over every element in our words array defined above. the `word` part of it could be anything, it's like defining a variable
if word not in punctuation: #If the word isn't in our list of punctuation marjs, we'll try and translate
first_letter = word[:1].lower() # word[:1] returns the first (1) letter of a word, if we changed it to two we'd get the first two letters
word_without_first_letter= word[1:] #word[1:] does a similar thing, but returns the word