Skip to content

Instantly share code, notes, and snippets.

@simonbromberg
simonbromberg / ConvertGithubImageLink.js
Last active September 25, 2020 16:49
Apple Automator Javascript to convert Github default embedded image to a resizable HTML img
@simonbromberg
simonbromberg / DecodePossibilities.swift
Last active July 10, 2020 04:57
Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded
/*
Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.
For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.
You can assume that the messages are decodable. For example, '001' is not allowed.
*/
import Foundation
@simonbromberg
simonbromberg / Heap.swift
Last active June 29, 2020 00:03
Heap Swift
struct Heap<Element> {
var elements: [Element]
let priorityFunction: (Element, Element) -> Bool
init(elements: [Element] = [], priorityFunction: @escaping (Element, Element) -> Bool) {
self.priorityFunction = priorityFunction
self.elements = []
for element in elements {
enqueue(element)
func registerKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChangeFrame(_:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
}
@objc func keyboardWillChangeFrame(_ notification: Foundation.Notification) {
guard let userInfo = notification.userInfo else {
return
}
let offset = UIScreen.main.bounds.height - (userInfo[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue.minY
func registerKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChangeFrame(_:)), name: NSNotification.Name.UIKeyboardWillChangeFrame, object: nil)
}
@objc func keyboardWillShow(_ notification: Foundation.Notification) {
guard let userInfo = notification.userInfo else {
return
}
@simonbromberg
simonbromberg / UUID.gs
Last active February 13, 2020 20:12 — forked from superstrong/Code.gs
Google Script to generate a UUID in Google Sheets - Forked to include menu that fills in UUIDs for active range
function getId() {
/**
* Imported from https://github.com/kyo-ago/UUID
* Robbie Mitchell, @superstrong
*/
/**
* UUID.core.js: The minimal subset of the RFC-compliant UUID generator UUID.js.
*
* @fileOverview

Keybase proof

I hereby claim:

  • I am simonbromberg on github.
  • I am shimmyb (https://keybase.io/shimmyb) on keybase.
  • I have a public key ASB34tUB3P7JuaAvVAAlIxrQLjO17d2EKOCuf0Cx5bDR8Ao

To claim this, I am signing this object:

extension Double {
// Given a value to round and a factor to round to,
// round the value to the nearest multiple of that factor.
mutating func round(toNearest: Double) {
self = (self / toNearest).rounded() * toNearest
}
// Given a value to round and a factor to round to,
// round the value DOWN to the largest previous multiple
// of that factor.
@simonbromberg
simonbromberg / UIGestureRecognizerState+LogString.swift
Created January 17, 2017 23:44
UIGestureRecognizerState+LogString
extension UIGestureRecognizerState {
var logString: String {
switch self {
case .began:
return "began"
case .cancelled:
return "cancelled"
case .changed:
return "changed"
case .ended:
@simonbromberg
simonbromberg / ListFonts.m
Last active September 6, 2023 03:35
List all fonts available on iOS device in console
// List all fonts on iPhone
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
for (NSString *family in familyNames) {
NSLog(@"Family name: %@", family);
fontNames = [UIFont fontNamesForFamilyName: family];
for (NSString *font in fontNames) {
NSLog(@" Font name: %@", font);
}