Skip to content

Instantly share code, notes, and snippets.

View junpluse's full-sized avatar

Jun Tanaka junpluse

View GitHub Profile
import Foundation
/// https://source.unsplash.com
public struct Unsplash {
public struct Source: RawRepresentable {
public let rawValue: String
public init(rawValue: String) {
self.rawValue = rawValue
}
import Foundation
/// A type that privides mutation interface for a wrapped value.
public struct Mutation<Value> {
/// The wrapped value.
public var value: Value
/// Creates an instance that wraps the given value.
///
/// - Parameter value: The value to store.
#!/usr/bin/swift
import Darwin
signal(SIGINT) { _ in
print("🆖")
}
let konami = "↑↑↓↓←→←→BA"
import Foundation
final class Subject<Value> {
let dispatchQueue: DispatchQueue
private static func makeDefaultDispatchQueue() -> DispatchQueue {
return DispatchQueue(label: String(reflecting: self), qos: .default, attributes: .concurrent)
}
private struct Observation {
@junpluse
junpluse / CVError.swift
Created December 15, 2016 11:21
CVReturn as Swift.Error
//
// CVError.swift
//
// Created by Jun Tanaka on 2016/12/13.
// Copyright © 2016 Jun Tanaka. All rights reserved.
//
import CoreVideo
public enum CVError: Int32, Error {
@junpluse
junpluse / EventPresenter.swift
Last active November 1, 2016 09:18
Dead simple one-to-many event presentation
//
// EventPresenter.swift
//
// Created by Jun Tanaka on 2016/10/27.
// Copyright © 2016 Jun Tanaka. All rights reserved.
//
import Foundation
private struct EventObserver<Event> {
@junpluse
junpluse / LayerView.swift
Last active April 27, 2016 11:27
UIView subclass for Core Animation lovers
import UIKit
final class LayerView<Layer: CALayer>: UIView {
var implicitAnimationsEnabled: Bool = false
var implicitlyAnimatableEvents: [String]? = nil
var genericLayer: Layer {
return layer as! Layer
}
@junpluse
junpluse / CAAnimation+On.swift
Created April 21, 2016 10:12
CAAnimation.on(started:stopped:)
import QuartzCore
private extension CAAnimation {
final class Delegate: NSObject {
var startHandlers = Array<StartHandler>()
var stopHandlers = Array<StopHandler>()
override func animationDidStart(anim: CAAnimation) {
startHandlers.forEach { $0(animation: anim) }
}
@junpluse
junpluse / AVPlayer+Repeat.swift
Last active May 12, 2021 15:28
AVQueuePlayer.repeatMode = .All
//
// AVPlayer+Repeat.swift
//
// Created by Jun Tanaka on 4/1/16.
// Copyright © 2016 eje Inc. All rights reserved.
//
import AVFoundation
private final class RepeatManager: NSObject {
@junpluse
junpluse / CAEAGLLayer+Snapshot.swift
Last active August 28, 2020 06:14
Take snapshot from CAEAGLLayer
import QuartzCore
import OpenGLES
extension CAEAGLLayer {
func takeSnapshot(from renderBuffer: GLuint? = nil) -> UIImage {
var bufferWidth: GLint = 0
var bufferHeight: GLint = 0
if let buffer = renderBuffer {
glBindRenderbufferOES(GLenum(GL_RENDERBUFFER_OES), buffer)