Skip to content

Instantly share code, notes, and snippets.

View maximkrouk's full-sized avatar
🇺🇦

Maxim Krouk maximkrouk

🇺🇦
View GitHub Profile
@figgleforth
figgleforth / Keyboard.swift
Last active January 13, 2022 13:18
Keyboard input for use with SpriteKit or SceneKit
//
// Keyboard.swift
//
// Created by Bojan Percevic on 5/21/15.
// Copyright (c) 2015 Bojan Percevic. All rights reserved.
//
import AppKit
enum Key: CUnsignedShort {
@PurpleBooth
PurpleBooth / README-Template.md
Last active July 25, 2024 13:33
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@odrobnik
odrobnik / gist:2751fb3ce32792b8a85d
Last active February 21, 2023 12:06
Swift: create CGPath from attributed string
func appendToPath(path: CGMutablePath)
{
let textPath = CGPathCreateMutable()
let attributedString = NSAttributedString(string: string)
let line = CTLineCreateWithAttributedString(attributedString)
// direct cast to typed array fails for some reason
let runs = (CTLineGetGlyphRuns(line) as [AnyObject]) as! [CTRun]
/*
Erica Sadun, http://ericasadun.com
Cross Platform Defines
Apple Platforms Only
Will update to #if canImport() when available
*/
@k06a
k06a / MLWAsyncAVPlayer.h
Last active September 7, 2023 11:51
Awesome optimized AVPlayer for smooth scrolling AVPlayerLayer inside UICollectionView/UITableView (tested on iOS10+)
#import <AVFoundation/AVFoundation.h>
@interface MLWAsyncAVPlayer : AVPlayer
@end
@chourobin
chourobin / MLWAsyncAVPlayer.h
Created June 20, 2017 04:23 — forked from k06a/MLWAsyncAVPlayer.h
Awesome optimized AVPlayer for smooth scrolling AVPlayerLayer inside UICollectionView/UITableView (tested on iOS10+)
#import <AVFoundation/AVFoundation.h>
@interface MLWAsyncAVPlayer : AVPlayer
@end
@reitzig
reitzig / Camelizer.swift
Created February 22, 2018 17:26
Convert Swift strings to camel case
fileprivate let badChars = CharacterSet.alphanumerics.inverted
extension String {
var uppercasingFirst: String {
return prefix(1).uppercased() + dropFirst()
}
var lowercasingFirst: String {
return prefix(1).lowercased() + dropFirst()
}
@shaps80
shaps80 / CGPoint+Target.swift
Last active March 21, 2024 18:44
Distance travelled after decelerating to zero velocity at a constant rate. The included Playground file shows how you can use it with a pan gesture as an example.
public extension CGPoint {
// The target points after decelerating to 0 velocity at a constant rate
func target(initialVelocity: CGPoint, decelerationRate: CGFloat = UIScrollView.DecelerationRate.normal.rawValue) -> CGPoint {
let x = self.x + self.x.target(initialVelocity: initialVelocity.x, decelerationRate: decelerationRate)
let y = self.y + self.y.target(initialVelocity: initialVelocity.y, decelerationRate: decelerationRate)
return CGPoint(x: x, y: y)
}
}
@4np
4np / HowTo use xcconfig or plist with SPM.md
Last active June 18, 2024 15:12
How to use a .xcconfig file and a .plist with a Swift Package Manager based project.

How to use a .xcconfig file and a .plist file with SPM

Worth a read for some more context.

Create a Package.xcconfig file

Create the file in the root of the project (where your Package.swift file lives as well), and use the following contents:

/// Package.xcconfig
@RuiAAPeres
RuiAAPeres / SwiftUIBindsWithReactiveSwift.swift
Last active December 12, 2023 09:30
Couple of methods to bridge ReactiveSwift with SwiftUI
import Combine
import ReactiveSwift
import SwiftUI
class AnySubscription: Subscription {
private let cancelable: Cancellable
init(cancelable: Cancellable) {
self.cancelable = cancelable