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 / gist:e830f34d1bcd88b8e7a97d21ca9dce24
Last active April 8, 2024 12:02
Compile libssh2 from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64)
#!/usr/bin/env zsh
set -e
# This script compiles libssh2 from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64).
SDK=macosx
SDK_VERSION="14.0"
# Set up a build directory
@mbernson
mbernson / build_apple.sh
Last active April 8, 2024 12:02
Compile OpenSSL from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64)
#!/usr/bin/env zsh
set -e
# This script compiles OpenSSL from source for macOS, creating a universal xcframework that works for Intel (x86_64) and Apple Silicon (arm64).
CROSS_COMPILE=`xcode-select --print-path`/Toolchains/XcodeDefault.xctoolchain/usr/bin/
CROSS_TOP=`xcode-select --print-path`/Platforms/MacOSX.platform/Developer
CROSS_SDK=MacOSX.sdk
ARCH="x86_64" # The x86_64 architecture preset also includes the ARM64 architecture.
@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
@mbernson
mbernson / MACAddress.swift
Last active February 5, 2024 16:20
MACAddress value type in Swift, for storing a MAC address
//
// MACAddress.swift
//
//
// Created by Mathijs on 23/01/2024.
//
import Foundation
/// Model for a standard MAC (Media Access Control) address, which consists of 6 bytes
@mbernson
mbernson / Alert+Error.swift
Last active January 25, 2024 13:55
Handling of (non-fatal) errors in SwiftUI
import SwiftUI
extension View {
/// Presents an alert when an error is present.
func alert<E: Error>(_ titleKey: LocalizedStringKey, error: Binding<E?>, buttonTitleKey: LocalizedStringKey = "Oke") -> some View {
modifier(ErrorAlert(error: error, titleKey: titleKey, buttonTitleKey: buttonTitleKey))
}
}
private struct ErrorAlert<E: Error>: ViewModifier {
@mbernson
mbernson / MarkdownView.swift
Created April 1, 2022 11:32
Customizing the styling attributes of the bold text in a Markdown attributed string in Swift.
import SwiftUI
import Foundation
struct MarkdownView: View {
var body: some View {
Text(try! AttributedString(markdown: "This is a **basic** _string_.", customBoldColor: .green))
.font(.title)
}
}
@mbernson
mbernson / ContentView.swift
Last active July 14, 2023 17:04
SwiftUI custom segmented control
import SwiftUI
struct ContentView: View {
@State var selected = "Foo"
var body: some View {
SegmentedControl(options: ["Foo", "Bar", "Baz"], selectedOption: $selected) { label in
Text(label)
}
}
@mbernson
mbernson / db.sql
Created June 14, 2012 10:30
PDO versus ext/mysql test
CREATE DATABASE `php_mysqltest`;
CREATE TABLE `test` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`test_int` int(11) DEFAULT NULL,
`test_float` float DEFAULT NULL,
`test_string` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@mbernson
mbernson / ContentView.swift
Last active January 31, 2023 08:17
Button that starts/stops a screen recording and present the user with the Apple-provided preview
// How to use it:
import SwiftUI
struct ContentView: View {
var body: some View {
RecordScreenButton()
}
}
@mbernson
mbernson / arrays.c
Created December 14, 2022 12:19
C array on the heap
#include <stdio.h>
#include <stdlib.h>
typedef struct Point {
int x;
int y;
} Point;
int main() {
int count = 2;