Skip to content

Instantly share code, notes, and snippets.

View SwiftsNamesake's full-sized avatar

Jonatan SwiftsNamesake

View GitHub Profile
class PromiseCancelledError: CancellableError {
var isCancelled: Bool {
return true
}
}
public class CancelablePromise<T> {
var promise:Promise<T>
var cancellable:TTCancellable!
@vegather
vegather / BlurryOverlayView.swift
Last active February 26, 2024 16:06
A simple view to animate in and out a blurry overlay. Use .blurIn() and .blurOut() to animate the blur. User interaction is passed through when the view is not blurry. NOTE: If you use storyboards, you need to drag out a UIVisualEffectView and set the class. It doesn't work if you drag out a plain old UIView.
class BlurryOverlayView: UIVisualEffectView {
private var animator: UIViewPropertyAnimator!
private var delta: CGFloat = 0 // The amount to change fractionComplete for each tick
private var target: CGFloat = 0 // The fractionComplete we're animating to
private(set) var isBlurred = false
private var displayLink: CADisplayLink!
override init(effect: UIVisualEffect?) {
super.init(effect: effect)
setup()
@mayoff
mayoff / StrokedPath.swift
Created July 17, 2017 04:10
stroked path playground
import UIKit
import ImageIO
import MobileCoreServices
import PlaygroundSupport
let documentFolderUrl = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
print(documentFolderUrl)
class ShapeView: UIView {
override class var layerClass: AnyClass { return CAShapeLayer.self }
@Akhu
Akhu / InvertMask+Layer.swift
Created May 12, 2017 12:53
Simple way to invert a mask on a layer with swift / quartzcore / ios
func mask(withRect rect: CGRect, inverse: Bool = false) {
let path = UIBezierPath(rect: rect)
let maskLayer = CAShapeLayer()
if inverse {
path.appendPath(UIBezierPath(rect: self.bounds))
maskLayer.fillRule = kCAFillRuleEvenOdd
}
maskLayer.path = path.CGPath
@levantAJ
levantAJ / AssetRecorderView.swift
Last active April 8, 2021 06:31
Record video, with auto detect faces, and overlay mask into faces
//
// AssetRecorderView.swift
// Snowball
//
// Created by Le Tai on 7/20/16.
// Copyright © 2016 Snowball. All rights reserved.
//
import UIKit
import AVFoundation
@alessaba
alessaba / PlaygroundsFrameworks.swift
Last active July 29, 2023 21:47
List of available frameworks in Swift Playgrounds over the years
// Swift Playgrounds Beta 1.0
import AVFoundation
import AVKit
import Accelerate
import Accounts
import AudioToolbox
import AudioUnit
import CFNetwork
import CoreAudio
import CoreAudioKit
@leilee
leilee / NSLayoutConstraint+Multiplier.swift
Created September 22, 2016 10:34
change multiplier property for NSLayoutConstraint
import UIKit
public extension NSLayoutConstraint {
func changeMultiplier(multiplier: CGFloat) -> NSLayoutConstraint {
let newConstraint = NSLayoutConstraint(
item: firstItem,
attribute: firstAttribute,
relatedBy: relation,
toItem: secondItem,
@CMCDragonkai
CMCDragonkai / short_circuiting_fold.md
Created February 5, 2016 09:10
Haskell: Short Circuiting Fold (Simulating Break in Imperative Languages)

Short Circuiting Fold

This pretty much explains it: http://crypto.stanford.edu/~blynn/haskell/foldl.html here I just review the article.

The rule of thumb is this:

  • if you want short circuiting on foldr, use a lazy on the right combiner
  • if you want short circuiting on foldl, use a lazy on the left combiner
@Jpoliachik
Jpoliachik / index.ios.js
Last active August 17, 2021 10:27
ReactNative LayoutAnimation Example
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View,
TouchableOpacity,
LayoutAnimation,
} from 'react-native';
@Dev1an
Dev1an / Easy NSLayoutConstraints.swift
Last active February 19, 2018 23:17
An easy way to create layout constraints with some custom swift operators.
//
// ConstraintOperators.swift
//
// Created by Damiaan Dufaux on 10/12/15.
// Copyright © 2015 Damiaan Dufaux. All rights reserved.
//
import Foundation
import UIKit