Skip to content

Instantly share code, notes, and snippets.

View StefKors's full-sized avatar
📟

Stef Kors StefKors

📟
View GitHub Profile
@JoshuaSullivan
JoshuaSullivan / ColorCubeHelper-swift2.swift
Last active April 17, 2024 10:48
Here are the Swift 2.3 and Swift 3.0 versions of the ColorCubeHelper class.
//
// ColorCubeHelper.swift
//
// Created by Joshua Sullivan on 10/01/16.
// Copyright © 2016 Joshua Sullivan. All rights reserved.
//
import UIKit
import Accelerate
@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@importRyan
importRyan / whenHovered.md
Last active April 6, 2024 06:54
Reliable SwiftUI mouse hover

Reliable mouseEnter/Exit for SwiftUI

Kapture 2021-03-01 at 14 43 39

On Mac, SwiftUI's .onHover closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.

It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.

import SwiftUI
@shaps80
shaps80 / UIMenu+ResultBuilder.swift
Created June 9, 2021 20:52
Adds ResultBuilder support to UIMenu to simplify creation
import SwiftUI
typealias Menu = UIMenu
typealias Action = UIAction
@resultBuilder
struct MenuElementBuilder {
static func buildBlock(_ components: UIMenuElement...) -> [UIMenuElement] { components }
}
@JadenGeller
JadenGeller / EventMonitor.swift
Last active April 2, 2024 02:06
for monitoring trackpad, touch, etc. events, useful in SwiftUI, similar to using CGTapCreate
import AppKit
struct EventMonitor: AsyncSequence {
typealias Element = NSEvent
enum Scope {
case local
case global
}
var scope: Scope = .local
import Foundation
import SwiftUI
// MARK: - Custom Button Style
struct MobileMeButtonStyle: ButtonStyle {
// MARK: Metrics
@ScaledMetric private var cornerRadius = 12
@ScaledMetric private var horizontalLabelPadding = 12
@ScaledMetric private var verticalLabelPadding = 8
@pseudosavant
pseudosavant / jSugar.js
Last active March 1, 2024 04:48
Utility function that adds in some jQuery-like syntactic sugar
// jQuery-like syntactic sugar. Only queries for one element. Does not loop over multiple like jQuery
function $(query) {
if (typeof query === 'undefined') throw 'No query provided to $';
var el;
if (typeof query.nodeType === 'string') {
el = query;
} else if (typeof query === 'string' && query[0] === '<') {
const container = document.createElement('div');
container.innerHTML = query;
@zats
zats / ContentView.swift
Last active February 17, 2024 10:23
Internal SF Symbols
struct ContentView: View {
var body: some View {
let names = [
["appstore.app.dashed", "buildings.3d", "emoji.chicken.face"],
["person.text.rectangle.and.nfc", "secure.element", "laugh.bubble.tapback.2.he"],
["apple.news", "apple.podcasts.square.stack", "apple.slice"],
]
VStack(spacing: 20) {
Grid(horizontalSpacing: 20, verticalSpacing: 20) {
ForEach(names, id: \.self) { nameRow in
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@chilts
chilts / alexa.js
Created October 30, 2013 09:27
Getting the Alexa top 1 million sites directly from the server, unzipping it, parsing the csv and getting each line as an array.
var request = require('request');
var unzip = require('unzip');
var csv2 = require('csv2');
request.get('http://s3.amazonaws.com/alexa-static/top-1m.csv.zip')
.pipe(unzip.Parse())
.on('entry', function (entry) {
entry.pipe(csv2()).on('data', console.log);
})
;