Skip to content

Instantly share code, notes, and snippets.

View iby's full-sized avatar
👻

Ian Bytchek iby

👻
View GitHub Profile
@bigmountainstudio
bigmountainstudio / Animation.md
Last active November 7, 2024 18:56 — forked from JeOam/Animation.md
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

  • view hierarchy
  • layer tree
@kevyworks
kevyworks / cli-greet.cmd.js
Last active August 27, 2019 05:52
NodeJS CLI Commander w/ separate commands and simple overrides for colors output help. Testing a sample output: `$ node cli.js`
"use strict";
/**
* @param {typeof import("./commander").Command} program Commander Instance
*/
module.exports = function(program) {
return program
.command("greet [name]")
.description("A greet command.")
.action((name) => {
@jeromecoupe
jeromecoupe / webstoemp-gulpfile.js
Last active April 11, 2025 08:17
Gulp 4 sample gulpfile.js. For a full explanation, have a look at https://www.webstoemp.com/blog/switching-to-gulp4/
"use strict";
// Load plugins
const autoprefixer = require("autoprefixer");
const browsersync = require("browser-sync").create();
const cp = require("child_process");
const cssnano = require("cssnano");
const del = require("del");
const eslint = require("gulp-eslint");
const gulp = require("gulp");
@joshbernfeld
joshbernfeld / CMTime+Codable.swift
Created January 11, 2018 05:07
Swift encoding/decoding support for CMTime
extension CMTime: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.value = try container.decode(CMTimeValue.self, forKey: .value)
self.timescale = try container.decode(CMTimeScale.self, forKey: .timescale)
self.flags = CMTimeFlags(rawValue: try container.decode(UInt32.self, forKey: .flags))
self.epoch = try container.decode(CMTimeEpoch.self, forKey: .epoch)
}
@mminer
mminer / NSImage+Oval.swift
Last active November 5, 2022 23:02
Creates a new NSImage with a circular mask.
import AppKit
extension NSImage {
/// Copies this image to a new one with a circular mask.
func oval() -> NSImage {
let image = NSImage(size: size)
image.lockFocus()
NSGraphicsContext.current?.imageInterpolation = .high
@brennanMKE
brennanMKE / ProcessBuffer.Swift
Last active November 2, 2023 09:25
Process a CMSampleBuffer to modify the audio using an AVAssetReader and AVAssetWriter in Swift
func processSampleBuffer(scale: Float, sampleBuffer: CMSampleBuffer, writerInput: AVAssetWriterInput) -> Bool {
guard let blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer) else {
return false
}
let length = CMBlockBufferGetDataLength(blockBuffer)
var sampleBytes = UnsafeMutablePointer<Int16>.allocate(capacity: length)
defer { sampleBytes.deallocate(capacity: length) }
guard checkStatus(CMBlockBufferCopyDataBytes(blockBuffer, 0, length, sampleBytes), message: "Copying block buffer") else {
return false
@lattner
lattner / async_swift_proposal.md
Last active December 28, 2024 11:11 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@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
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
private let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
private var array = [Element]()
public init() { }
@Sorix
Sorix / AsynchronousOperation.swift
Last active May 22, 2024 07:15
Subclass of NSOperation (Operation) to make it asynchronous in Swift 3, 4, 5
// Created by Vasily Ulianov on 09.02.17, updated in 2019.
// License: MIT
import Foundation
/// Subclass of `Operation` that adds support of asynchronous operations.
/// 1. Call `super.main()` when override `main` method.
/// 2. When operation is finished or cancelled set `state = .finished` or `finish()`
open class AsynchronousOperation: Operation {
public override var isAsynchronous: Bool {