Skip to content

Instantly share code, notes, and snippets.

globulus /
Created August 12, 2022 09:13
Fix mqtt.js for use in React and Webpack 5
#!/usr/bin/env bash
set -e
cd node_modules/mqtt
cat > webpack.config.js << EOF
const webpack = require('webpack')
module.exports = {
entry: "./lib/connect/index.js",
globulus / View.swift
Created June 14, 2022 08:04
Chart Scan Line / Lollipop in SwiftUI with Charts Framework
// Check out
import SwiftUI
import Charts
struct FoodIntake: Hashable {
let date: Date
let calories: Int
globulus / Weighted.swift
Created December 11, 2021 13:05
Weighted HStack and VStack in SwiftUI
// Full recipe at
import SwiftUI
class WeightedProxy {
let kind: Kind
var geo: GeometryProxy? = nil
private(set) var totalWeight: CGFloat = 0
init(kind: Kind) {
globulus / EnhancedVideoPlayer.swift
Created September 12, 2021 20:02
Enhanced SwiftUI Video Player
// Full recipe at
import SwiftUI
import AVKit
import Foundation
struct EnhancedVideoPlayer<VideoOverlay: View>: View {
@StateObject private var viewModel: ViewModel
@ViewBuilder var videoOverlay: () -> VideoOverlay
globulus / SwipeActions.swift
Last active August 21, 2023 00:02
Add custom row swipe actions to a SwiftUI List
// Full recipe at
import SwiftUI
// Button in swipe action, renders text or image and can have background color
struct SwipeActionButton: View, Identifiable {
static let width: CGFloat = 70
let id = UUID()
let text: Text?
globulus / HyperlinkText.swift
Created August 26, 2021 14:28
SwiftUI Text with NSAttributedString, HTML or Markdown with tappable Hyperlinks
// full recipe at
import SwiftUI
import SwiftUIFlowLayout
import MarkdownKit
struct HyperlinkTest: View {
var body: some View {
VStack {
HyperlinkText(html: "To <b>learn more</b>, <i>please</i> feel free to visit <a href=\"\">SwiftUIRecipes</a> for details, or check the <code>source code</code> at <a href=\"\">Github page</a>.")
HyperlinkText(markdown: "To **learn more**, *please* feel free visit [SwiftUIRecipes]( for details, or check the `source code` at [Github page](")
globulus / SwiftUIFreeformDrawing.swift
Created June 29, 2021 15:27
SwiftUI freeform drawing
struct DrawingPath {
private var points = [CGPoint]()
private var breaks = [Int]()
mutating func addPoint(_ point: CGPoint) {
mutating func addBreak() {
globulus / HTMLText.swift
Created May 27, 2021 07:08
SwiftUI Text with HTML via NSAttributedString
// full recipe at
extension Text {
init(html htmlString: String,
raw: Bool = false,
size: CGFloat? = nil,
fontFamily: String = "-apple-system") {
let fullHTML: String
if raw {
fullHTML = htmlString
} else {
globulus / DIFramework.swift
Created December 16, 2020 10:02
Basic DI framework in Swift
import Foundation
public struct Service {
public enum LifeCycle {
case singleton
case factory
/// Holds the lifecycle of the current service
public var cycle: LifeCycle