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 / 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 / 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;
@mbernson
mbernson / MarkdownExample.swift
Created August 2, 2022 13:35
Example of custom styles using Markdown support in SwiftUI Text.
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 April 26, 2022 13:07
UIScrollView wrapped for SwiftUI, with support for pull to refresh using the refreshable modifier
//
// 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 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 / CGAffineTransform+FlipVertical.swift
Created April 1, 2022 08:51
Flip vertical using CGAffineTransform
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 April 1, 2022 11:32
MFMailComposeViewController wrapped for SwiftUI
//
// 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 February 20, 2022 15:24
Q42 logo as a SwiftUI view
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 February 19, 2022 14:43
Dobbelspel voor CoderDojo
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