Skip to content

Instantly share code, notes, and snippets.

View mbernson's full-sized avatar
👨‍💻
Coding...

Mathijs Bernson mbernson

👨‍💻
Coding...
View GitHub Profile
@mbernson
mbernson / TimePicker.swift
Created January 20, 2022 09:12
UIDatePicker wrapper in SwiftUI
//
// TimePicker.swift
//
// Created by Tobias Stikvoort on 16/11/2021.
//
import SwiftUI
import UIKit
struct TimePicker: UIViewRepresentable {
@mbernson
mbernson / LottieView.swift
Created January 20, 2022 09:05
Lottie view wrapper in SwiftUI
//
// LottieView.swift
//
// Created by Mathijs Bernson on 27/10/2021.
//
import SwiftUI
import Lottie
struct LottieView: UIViewRepresentable {
@mbernson
mbernson / Snow.swift
Last active December 5, 2021 21:28
A view for your iOS app to draw some falling snow on top of your content. :)
//
// Snow.swift
//
// Created by Mathijs Bernson on 05/12/2021.
//
import UIKit
import SwiftUI
/// A transparent view that displays falling snow on top of itself.
@mbernson
mbernson / Spinner.swift
Created November 15, 2021 15:37
UIActivityIndicatorView in SwiftUI
import SwiftUI
import UIKit
struct Spinner: UIViewRepresentable {
let style: UIActivityIndicatorView.Style
@State var animating: Bool = true
func makeUIView(context: Context) -> UIActivityIndicatorView {
UIActivityIndicatorView(style: style)
}
@mbernson
mbernson / ReadableContentWidth.swift
Last active August 26, 2021 06:35
SwiftUI view modifier that constrains the width of a view to be no bigger than the readable width.
import SwiftUI
/// View modifier that constrains the width of a view to be no bigger than the readable width.
struct ReadableContentWidth: ViewModifier {
private let measureViewController = UIViewController()
@State private var orientation: UIDeviceOrientation = UIDevice.current.orientation
func body(content: Content) -> some View {
content
@mbernson
mbernson / automations.yaml
Created February 15, 2021 13:52
Home Assistant - Start Roomba using actionable push notification
- id: '1613375678079'
alias: Ask to start cleaning
trigger:
- platform: zone
entity_id: person.mathijs
zone: zone.home
event: leave
condition:
# I added this step in the UI, don't know how to find the device_id otherwise
# - condition: device
@mbernson
mbernson / formatting.sh
Created September 25, 2020 08:06
Automatically format Swift files that have changed before committing
#!/usr/bin/env bash
# formatting.sh - Automatically formats Swift files that have changed before committing.
DIFF_FILTER="ACMR" # Only format files that have been added, copied, modified or renamed.
STAGED_FILES=$(git diff --cached --name-only --diff-filter=$DIFF_FILTER "*.swift")
NOT_STAGED_FILES=$(git diff --name-only --diff-filter=$DIFF_FILTER "*.swift")
# Skip formatting for partially staged files. This is done by subtracting any files that git also considers unstaged from the list.
FILES_TO_FORMAT=($(comm -23 <(printf "%s\n" "${STAGED_FILES[@]}" | sort) <(printf "%s\n" "${NOT_STAGED_FILES[@]}" | sort)))
@mbernson
mbernson / x
Last active December 5, 2024 09:53
X - Opens the Xcode workspace/project or Swift package in your current working directory using Xcode.
#!/usr/bin/env ruby
XCODE_PATH = File.expand_path(File.join(`xcode-select -p`.chomp, '../..'))
def open_cmd(pattern)
files = Dir.glob(pattern)
`open -a "#{XCODE_PATH}" "#{files.first}"` and exit if files.count == 1
end
open_cmd '*.xcworkspace'
@mbernson
mbernson / create_color_assets.php
Last active June 25, 2019 13:09
Generate color assset catalog
<?php
// Configuration
$source_file = 'Theme.swift';
$output_asset_catalog = 'MyApp/Resources/Colors.xcassets';
//
function mkdir_if_not_exists($directory) {
if (!is_dir($directory)) {
@mbernson
mbernson / camera.yaml
Last active March 9, 2024 23:45
esphome configuration for the TTGO T-Camera ESP32-WROVER-B
# esphome configuration for the TTGO T-Camera ESP32-WROVER-B
# https://www.aliexpress.com/item/TTGO-T-Camera-ESP32-WROVER-B-PSRAM-Camera-Module-ESP32-WROVER-OV2640-Camera-Module-0-96/32966036489.html
# I use this 3D-printed case for the device:
# https://www.thingiverse.com/thing:3540059
esphome:
name: woonkamer
platform: ESP32
board: esp32dev