Skip to content

Instantly share code, notes, and snippets.

View buh's full-sized avatar
📦
Swift

Alexey Bukhtin buh

📦
Swift
  • Amsterdam
View GitHub Profile
@antonkudin
antonkudin / spherefog.shader
Last active February 8, 2025 10:19
Spherical fog unity shader
// original from https://forum.unity3d.com/threads/share-volume-fog-shader.147323/
Shader "Effect/SphereFog" {
Properties {
_FogColor ("Fog Color", Color) = (1,1,1,1)
[space]
_Density ("Density", Float) = 1
_Power ("Power/gamma", Float) = 4
_Offset ("Offset", Range(-.1,.1)) = -0.003
[space]
_NearbyOffset ("Nearby Offset", Float) = -1
@dkun7944
dkun7944 / ContentView.swift
Created July 31, 2023 03:36
AirDrop iOS 17 Swift.Shader Animation
//
// ContentView.swift
// Airdrop Demo
//
// Created by Daniel Kuntz on 7/30/23.
//
import SwiftUI
struct ContentView: View {
@dkun7944
dkun7944 / CDView.swift
Last active March 12, 2025 09:20
SwiftUI + Swift.Shader CD
//
// CDView.swift
// CD
//
// Created by Daniel Kuntz on 7/3/23.
//
import SwiftUI
struct ShapeWithHole: Shape {
@insidegui
insidegui / FixSwiftUIMaterialInPreviews.m
Created May 13, 2022 21:27
Fixes SwiftUI's Material not being rendered correctly in Xcode previews
#if DEBUG
/*
This fixes SwiftUI previews not rendering translucent materials correctly by
swizzling a couple of properties on NSWindow.
Just drop into your project and add to the target being previewed (or something it links against).
Notice the #if DEBUG, so this code won't end up in release builds. It also checks for the
XCODE_RUNNING_FOR_PREVIEWS environment variable so that it won't affect regular debug builds of the app.
@insidegui
insidegui / reloadplugins.sh
Created January 29, 2022 23:00
Make your Mac app's extensions immediately available on macOS with a run script build phase
# Add this to a "Run Script" build phase in your app's main target, as the last step.
# It will use the pluginkit command-line tool to force the plugin system on macOS to add your extensions to its database, making them available.
# I made this specifically for widgets, but it should work for pretty much any extension type (appex bundle).
find $CODESIGNING_FOLDER_PATH -name '*.appex' -exec pluginkit -a {} \;
@zhaorui
zhaorui / keypad.swift
Created November 11, 2021 13:52
A console app print all key events written by swift
import Cocoa
import Foundation
@discardableResult
func acquirePrivileges() -> Bool {
let accessEnabled = AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary)
if accessEnabled != true {
print("You need to enable the keylogger in the System Prefrences")
// Simplified version of https://gist.github.com/anandabits/d9494d14fef221983ff4f1cafa318d47#file-areequatablyequal-swift
func isEqual(x: Any, y: Any) -> Bool {
func f<LHS>(_ lhs: LHS) -> Bool {
let p = Wrapper<LHS>.self as? AnyEquatable.Type
return p?.isEqual(x, y) ?? false
}
return _openExistential(x, do: f)
}
@apptekstudios
apptekstudios / CustomPicker.swift
Last active May 28, 2021 02:35
A variation on the picker designed by Federico Zanetello in his blog post (https://fivestars.blog/swiftui/inspecting-views.html) that allows any type of content to be used
//
// CustomPicker.swift
//
// Created by T Brennan on 27/3/21.
//
import SwiftUI
struct ContentView: View {
@State private var selection: Int? = 0
@stuartcarnie
stuartcarnie / NSEvent+Publisher.swift
Last active March 5, 2023 19:08
Combine Publisher support for NSEvent.addLocalMonitorForEvents
@available(macOS 10.15, *)
extension NSEvent {
static func publisher(scope: Publisher.Scope, matching: EventTypeMask) -> Publisher {
return Publisher(scope: scope, matching: matching)
}
public struct Publisher: Combine.Publisher {
public enum Scope {
case local, global
}
@smic
smic / BorderlessWindow.swift
Last active July 7, 2023 20:19
Extension to create borderless windows in SwiftUI
import SwiftUI
extension CGRect {
fileprivate func point(anchor: UnitPoint) -> CGPoint {
var point = self.origin
point.x += self.size.width * anchor.x
#if os(macOS)
point.y += self.size.height * (1 - anchor.y)
#else
point.y += self.size.height * anchor.y