Skip to content

Instantly share code, notes, and snippets.

@shavit
shavit / CoreImageFilters.swift
Created May 12, 2018 18:13
CIFilter opacity
/*
Change the opacity of a CIFilter.
*/
func changeOpacity(to opacity: CGFloat, on filter: CIFilter, original image: UIImage) -> CIImage? {
guard let backgroundImage: CIImage = CIImage(image: image) else { fatalError() }
// The CIColorMatrix filter, will contain the requested filter and control its opacity
guard let overlayFilter: CIFilter = CIFilter(name: "CIColorMatrix") else { fatalError() }
let overlayRgba: [CGFloat] = [0, 0, 0, opacity]
let alphaVector: CIVector = CIVector(values: overlayRgba, count: 4)
#!/usr/bin/env swift
//
// faceExtraction.swift
// FaceITDetection
//
// Extracts faces detected in images
//
// Created by NovaTec GmbH on 16.08.17.
// Copyright © 2017 NovaTec GmbH. All rights reserved.
//
@ha1f
ha1f / CIFilter+Extension.swift
Last active February 20, 2024 08:14
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
@smileyborg
smileyborg / SimulatedSlowLoadingImage.swift
Created August 5, 2017 02:06
Snippet showing how to create an NSItemProvider with a simulated delay for loading an image
import UIKit
import MobileCoreServices
let image = UIImage() // your actual image
let itemProvider = NSItemProvider()
itemProvider.registerDataRepresentation(forTypeIdentifier: kUTTypeJPEG as String, visibility: .all) { (completionBlock) -> Progress? in
let unitsOfWork = 10 + Int64(arc4random_uniform(UInt32(10))) // 10 - 19 units
let progress = Progress.discreteProgress(totalUnitCount: unitsOfWork)
@fzwo
fzwo / LegacyDocsets.md
Last active May 12, 2025 06:19
Download and view old Apple developer documentation

How to download and view legacy documentation from Apple (no need to sign in to your dev account)

  1. Download the docset index XML.
  2. Find the docset you want (there are some with URL https://apple.com/none.dmg; ignore them - you will find them again further down the file with a working URL).
  3. Download the dmg. It's probably around a gigabyte or so.
  4. "Install" the .pkg file somewhere on your disk. If you don't trust the installer, do it manually:
    1. Find the largest file, named Payload, and extract it using The Unarchiver.
    2. This creates a new, even larger file, probably named Payload-1.
    3. Extract Payload-1 using The Unarchiver.
  5. After many minutes of extracting, we have our .docset file.
/*
Erica Sadun, http://ericasadun.com
Cross Platform Defines
Apple Platforms Only
Will update to #if canImport() when available
*/
@cemolcay
cemolcay / NoiseMap.swift
Created November 13, 2016 16:56
Having fun with GKNoiseMap procedurally generated tile maps
//: Playground - noun: a place where people can play
import UIKit
import SpriteKit
import GameplayKit
enum NoiseTileType: CustomStringConvertible {
case ocean
case grass
case mountain
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@IBAction func fontFaceChanged(sender: NSPopUpButton) {
let newIDX = sender.indexOfSelectedItem
if let currentFont = textView?.typingAttributes[NSFontAttributeName] as? NSFont {
let newFaceName = fontFaceNames[newIDX]
if let newFont = NSFontManager.sharedFontManager().convertFont(currentFont, toFace: newFaceName) {
applyNewAttributes([NSFontAttributeName: newFont])
}
}
}
@kristopherjohnson
kristopherjohnson / LowPassFilterSignal.swift
Last active June 10, 2024 05:30
Simple implementation of low-pass filter
struct LowPassFilterSignal {
/// Current signal value
var value: Double
/// A scaling factor in the range 0.0..<1.0 that determines
/// how resistant the value is to change
let filterFactor: Double
/// Update the value, using filterFactor to attenuate changes
mutating func update(newValue: Double) {