Skip to content

Instantly share code, notes, and snippets.

View iSapozhnik's full-sized avatar
🎯
Focusing

Sapozhnik Ivan iSapozhnik

🎯
Focusing
View GitHub Profile
@iSapozhnik
iSapozhnik / gist:51b2d81e5969f10df8fed39a0067320a
Created December 29, 2022 13:01 — forked from sdsykes/gist:5c2c0c2a41396aead3b7
Windows on a space (using private CGS)
/// header
id CGSCopyManagedDisplaySpaces(int conn);
int _CGSDefaultConnection();
id CGSCopyWindowsWithOptionsAndTags(int conn, unsigned owner, NSArray *spids, unsigned options, unsigned long long *setTags, unsigned long long *clearTags);
// code
int spaceNumber = 0; // the space you want to get the windows for. numbering starts at 0.
@iSapozhnik
iSapozhnik / NSFont+Extensions.swift
Created December 20, 2021 21:39
Rounded NSFont
extension NSFont {
class func roundedFont(ofSize size: CGFloat, weight: NSFont.Weight) -> NSFont {
let systemFont = NSFont.systemFont(ofSize: size, weight: weight)
guard let descriptor = systemFont.fontDescriptor.withDesign(.rounded),
let roundedFont = NSFont(descriptor: descriptor, size: size) else {
return systemFont
}
return roundedFont
}
func test(with identifier: String = #function, body: (XCTestExpectation) -> Void) {
let expectation = expectation(description: identifier)
body(expectation)
waitForExpectations(timeout: 0.5)
}
func testAscending() {
let a = [1]
test { expectation in
@iSapozhnik
iSapozhnik / email_icon.svg
Last active August 20, 2021 12:25
Pixelated SwiftUI image
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iSapozhnik
iSapozhnik / UIStackView+Extensions.swift
Created April 23, 2020 19:30
UIStackView with custom spacing after arranged subview
extension UIStackView {
func setSpacing(_ spacing: CGFloat, after arrangedSubview: UIView) {
guard let index = arrangedSubviews.firstIndex(of: arrangedSubview) else { return }
let spaceView = UIView()
spaceView.translatesAutoresizingMaskIntoConstraints = false
switch axis {
case .horizontal:
spaceView.widthAnchor.constraint(equalToConstant: spacing).isActive = true
@iSapozhnik
iSapozhnik / NSView+NibLoadable.swift
Last active April 22, 2020 17:58
Creating NSView from XIB file
// For views that can be loaded from nib file
protocol NibLoadable {
// Name of the nib file
static var nibName: String { get }
static func createFromNib(in bundle: Bundle) -> Self
}
extension NibLoadable where Self: NSView {
// Default nib name must be same as class name
extension NSImage {
func appIcon(h:CGFloat = 35) -> NSImage {
let size = NSSize(width: h, height: h)
let cornerRadius: CGFloat = h/5
guard self.isValid else {
return self
}
let newImage = NSImage(size: size)
@iSapozhnik
iSapozhnik / NSBezierPath+Extensions.swift
Last active April 4, 2020 22:40
Converting NSBezierPath to CGPAth
extension NSBezierPath {
var cgPath: CGPath {
let path = CGMutablePath()
var points = [CGPoint](repeating: .zero, count: 3)
for i in 0 ..< self.elementCount {
let type = self.element(at: i, associatedPoints: &points)
switch type {
case .moveTo:
path.move(to: points[0])
class GradientView: UIView {
var gradientLayer: CAGradientLayer!
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder: NSCoder) {
super.init(coder: coder)