Skip to content

Instantly share code, notes, and snippets.

Avatar

Mathijs Bernson mbernson

View GitHub Profile
@mbernson
mbernson / ContentView.swift
Last active Jan 26, 2023
Button that starts/stops a screen recording and present the user with the Apple-provided preview
View ContentView.swift
// How to use it:
import SwiftUI
struct ContentView: View {
var body: some View {
RecordScreenButton()
}
}
@mbernson
mbernson / arrays.c
Created Dec 14, 2022
C array on the heap
View arrays.c
#include <stdio.h>
#include <stdlib.h>
typedef struct Point {
int x;
int y;
} Point;
int main() {
int count = 2;
@mbernson
mbernson / MarkdownExample.swift
Created Aug 2, 2022
Example of custom styles using Markdown support in SwiftUI Text.
View MarkdownExample.swift
import SwiftUI
import PlaygroundSupport
import Foundation
struct MarkdownView: View {
var body: some View {
Text(try! AttributedString(markdown: "This is a **basic** _string_. Italic bits are red. All the **bold** bits are _coloured_ **green**! And [this is a link!](https://q42.nl/).", customBoldColor: .green, customItalicColor: .red))
.font(.title)
}
}
@mbernson
mbernson / ScrollViewWrapper.swift
Last active Apr 26, 2022
UIScrollView wrapped for SwiftUI, with support for pull to refresh using the refreshable modifier
View ScrollViewWrapper.swift
//
// ScrollViewWrapper.swift
//
// Created by Mathijs Bernson on 10/03/2022.
// Copyright © 2022 Q42. All rights reserved.
//
import SwiftUI
import UIKit
@mbernson
mbernson / MarkdownView.swift
Created Apr 1, 2022
Customizing the styling attributes of the bold text in a Markdown attributed string in Swift.
View MarkdownView.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 / CGAffineTransform+FlipVertical.swift
Created Apr 1, 2022
Flip vertical using CGAffineTransform
View CGAffineTransform+FlipVertical.swift
import UIKit
extension CGAffineTransform {
static func flipVertical(height: CGFloat) -> Self {
CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: height)
}
}
@mbernson
mbernson / MailComposeView.swift
Last active Apr 1, 2022
MFMailComposeViewController wrapped for SwiftUI
View MailComposeView.swift
//
// MailComposeView.swift
//
// Created by Mathijs Bernson on 08/03/2022.
// Copyright © 2022 Q42. All rights reserved.
//
import SwiftUI
import MessageUI
@mbernson
mbernson / q42.swift
Last active Feb 20, 2022
Q42 logo as a SwiftUI view
View q42.swift
import SwiftUI
public struct Q42: View {
private let bounds = CGRect(x: 0, y: 0, width: 333, height: 500)
public init() {}
private var balloon: some Shape {
Fit(path: Path("166.6 500 m 214.8 345.7 273 319 316.9 232.9 c 371.2 126.5 282.5 0 166.6 0 c 50.7 0 -37.9 126.5 16.4 232.9 c 60.2 319 118.4 345.7 166.6 500 c h")!, bounds: bounds)
}
@mbernson
mbernson / dobbelspel.py
Created Feb 19, 2022
Dobbelspel voor CoderDojo
View dobbelspel.py
from random import randint
# Gooi de dobbelsteen
answer = randint(1, 6)
while True:
guess = int(input('Raad een getal tussen 1 en 6: '))
if guess == answer:
print("Dat was het juiste antwoord!")
break
@mbernson
mbernson / TimePicker.swift
Created Jan 20, 2022
UIDatePicker wrapper in SwiftUI
View TimePicker.swift
//
// TimePicker.swift
//
// Created by Tobias Stikvoort on 16/11/2021.
//
import SwiftUI
import UIKit
struct TimePicker: UIViewRepresentable {