Skip to content

Instantly share code, notes, and snippets.

View djmadcat's full-sized avatar

Alexey Aleshkov djmadcat

  • Yandex, LLC
  • Moscow
View GitHub Profile
@pgherveou
pgherveou / concatMap.swift
Last active December 20, 2017 16:36
RxSwift + concatMap
import PlaygroundSupport
import RxSwift
PlaygroundPage.current.needsIndefiniteExecution = true
/// ConcatMap Operator
/// Runs all observable sequences in parallel and concat their elements.
extension ObservableType {
func concatMap<T>(project: @escaping (E) -> Observable<T>) -> Observable<T> {
return self.map { (element) -> Observable<T> in
@hotpaw2
hotpaw2 / RecordAudio.swift
Last active April 3, 2024 03:10
Swift Audio Recording class. Reads buffers of input samples from the microphone using the iOS RemoteIO Audio Unit API
//
// RecordAudio.swift
//
// This is a Swift class (updated for Swift 5)
// that uses the iOS RemoteIO Audio Unit
// to record audio input samples,
// (should be instantiated as a singleton object.)
//
// Created by Ronald Nicholson on 10/21/16.
// Copyright © 2017,2019 HotPaw Productions. All rights reserved.
@douglashill
douglashill / covariance.m
Last active November 25, 2016 14:53
A quick look at variance with Objective-C generics. `NSSet` is covariant on its `ObjectType`, while `NSHashTable` is invariant. Contravariance is also supported.
@import Foundation;
@interface ContravariantCollection<__contravariant ObjectType> : NSObject
@end
@implementation ContravariantCollection
@end
void stringSetThing(NSSet<NSString *> *set) {
}
@garmstro
garmstro / QuadTree.swift
Created May 6, 2015 19:22
QuadTree Class In Swift
//
// QuadTree.swift
//
// Created by Geoff Armstrong on 5/5/15.
// Copyright (c) 2015 Geoff Armstrong. All rights reserved.
//
import UIKit
/**
@JadenGeller
JadenGeller / Matrix Examples.swift
Last active August 10, 2023 10:03
Matrices in Swift
// Numerical matrix examples
let x: Matrix = [[10, 9, 8], [3, 2, 1]]
let y: Matrix = [[1, 2, 3], [4, 5, 6]]
let z: Matrix = [[1, 2], [3, 4], [5, 6]]
x + y // [[11, 11, 11], [7, 7, 7]]
x * y // [[10, 18, 24], [12, 10, 6]]
2 * x // [[20, 18, 16], [6, 4, 2]]
y ** z // [[22, 28], [49, 64]]
@preble
preble / WeakSet.swift
Last active July 13, 2023 06:45
A pure Swift weak set.
//
// Created by Adam Preble on 2/19/15.
//
/// Weak, unordered collection of objects.
public struct WeakSet<T where T: AnyObject, T: Hashable> {
typealias Element = T
/// Maps Element hashValues to arrays of Entry objects.
/// Invalid Entry instances are culled as a side effect of add() and remove()
@JeOam
JeOam / Animation.md
Last active February 18, 2024 21:18
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

Author: https://www.cyanhall.com/

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:

@wangkuiyi
wangkuiyi / pre-commit-clang-format
Last active August 19, 2021 14:04
Git pre-commit hook that invokes clang-format to reformat C/C++/Objective-C source code.
#!/bin/bash
# git pre-commit hook that runs an clang-format stylecheck.
# Features:
# - abort commit when commit does not comply with the style guidelines
# - create a patch of the proposed style changes
# modifications for clang-format by rene.milk@wwu.de
# This file is part of a set of unofficial pre-commit hooks available
# at github.
@framkant
framkant / gist:6daed7f6145af958f0bc
Created December 7, 2014 09:55
A C99 version (needed for my own purposes)
// -------------------------------------------------------------------------------
// CoreAudio continuous play test
// (c) 2014 by Arthur Langereis (@zenmumbler)
// created: 2014-12-07
//
// As part of my efforts for stardazed and to create a Mac OS X version of
// Handmade Hero.
//
// compile with:
// clang++ -std=c++11 -stdlib=libc++ -framework AudioToolbox catest.cpp -o catest
@natecook1000
natecook1000 / openRanges.swift
Last active May 27, 2021 19:37
Open-ended range operators for Swift
// Open-ended range operators
//
// 100... is equivalent to 100...Int.max
// ...-100 is equivalent to Int.min...-100
// ..<3 is equivalent to Int.min..<3
import Swift
/// Conforming types provide static `max` and `min` constants.
protocol MinMaxType {