Skip to content

Instantly share code, notes, and snippets.

@INCHMAN1900
INCHMAN1900 / ContentView.swift
Created October 20, 2024 18:48
SwiftUI view with window resizing.
//
// ContentView.swift
// window-demo
//
// Created by Asia Fu on 2024/10/20.
//
import SwiftUI
struct WindowAccessor: NSViewRepresentable {
@INCHMAN1900
INCHMAN1900 / NSView+Drag.swift
Created September 1, 2024 12:50
Invoke beginDraggingSession programmatically in NSView
class NSView {
override func mouseDown(with event: NSEvent) {
guard event.clickCount <= 2 else { return }
let location = view.convert(event.locationInWindow, from: nil)
let eventMask: NSEvent.EventTypeMask = [.leftMouseUp, .leftMouseDragged]
let timeout = NSEvent.foreverDuration
var dragInitiated = false
view.window?.trackEvents(matching: eventMask, timeout: timeout, mode: .eventTracking, handler: { (event, stop) in
@INCHMAN1900
INCHMAN1900 / ContentView.swift
Created June 17, 2024 04:43
ScrollView with divider
struct SearchView: NSViewRepresentable {
typealias NSViewType = NSSearchField
func makeNSView(context: Context) -> NSSearchField {
return NSSearchField()
}
func updateNSView(_ nsView: NSSearchField, context: Context) {
}
@INCHMAN1900
INCHMAN1900 / Hilbert_Curve.pde
Created October 11, 2023 07:39
Create Hilbert Curve in under 40 lines of code in Processing.
void setup() {
size(800, 800);
background(255);
noFill();
translate(width * 0.5, height * 0.5); // center of the curve.
hilbert_curve(6, width);
}
void hilbert_curve(int n, float size) {
@INCHMAN1900
INCHMAN1900 / example.html
Last active May 31, 2020 04:24
JavaScript snippets to create full page applications.
<!DOCTYPE html>
<!-- full page template -->
<!-- created for single-page personal website -->
<html>
<head>
<meta charset='utf8'>
<style>
body {