Skip to content

Instantly share code, notes, and snippets.

View AliSoftware's full-sized avatar

Olivier Halligon AliSoftware

View GitHub Profile
@AliSoftware
AliSoftware / Image+Outline-CIFilter.swift
Created May 26, 2023 16:01
A demo of applying CIFilters to Swift Images, trying to apply a glow effect
import SwiftUI
import UIKit
import CoreImage
import PlaygroundSupport
extension CIImage {
convenience init(_ uiImage: UIImage) {
if let cgImage = uiImage.cgImage {
self.init(cgImage: cgImage)
@AliSoftware
AliSoftware / CountedSet.swift
Last active October 23, 2021 01:36
CountedSet custom implementation in Swift
struct CountedSet<Element: Hashable> {
private var storage: [Element: Int] = [:]
}
/// Creating a CountedSet from a Dictionary or DictionaryLiteral
///
/// let example: CountedSet = ["a": 1, "b": 3, "c": 42]
extension CountedSet: ExpressibleByDictionaryLiteral {
init(dictionaryLiteral elements: (Element, Int)...) {
self.storage = Dictionary(uniqueKeysWithValues: elements)
@AliSoftware
AliSoftware / pod_stats.rb
Last active March 12, 2021 13:42
Tools to investigate the state of our internal pods at a8c
#!/usr/bin/env ruby
require 'json'
require 'yaml'
require 'open-uri'
# [Array<String>] List of iOS/macOS apps
app_dirs = ['WordPress-iOS', 'woocommerce-ios', 'simplenote-ios', 'simplenote-macos', 'autoproxxy']
specs_cache = File.join(__dir__, 'pod_stats.cache')
@AliSoftware
AliSoftware / git-groom
Last active December 7, 2021 15:46
Sync git working copies' trunk and develop branches and prune local and remote deleted/orphan branches
#!/bin/bash -euo pipefail
#
# Author: O.Halligon
# Jan 2021
#
# Help
if [ "${1:-}" == "-h" -o "${1:-}" == "--help" ]; then
BASENAME=${0##*/}
@AliSoftware
AliSoftware / RegEx.swift
Created March 16, 2020 15:01
Attempt at a nicer API for Swift RegEx (WIP)
// Simple wrapper around NSRegularExpression to provide a swiftier API and, ability to have matches exposing Range instead of NSRange
import Foundation
struct RegEx<Names> {
let regex: NSRegularExpression
init(pattern: String, options: NSRegularExpression.Options = []) throws {
self.regex = try NSRegularExpression(pattern: pattern, options: options)
}
//: ## Demo
struct User: CustomStringConvertible {
let name: String
let age: Int
var description: String { "\(name) (\(age))" }
}
let users = [
User(name: "Bob", age: 22),
@AliSoftware
AliSoftware / Demo.swift
Last active October 31, 2023 12:25
NestableCodingKey: Nice way to define nested coding keys for properties
struct Contact: Decodable, CustomStringConvertible {
var id: String
@NestedKey
var firstname: String
@NestedKey
var lastname: String
@NestedKey
var address: String
enum CodingKeys: String, NestableCodingKey {
@AliSoftware
AliSoftware / CustomMatcher.swift
Last active January 5, 2020 21:40
Add custom pattern matching to make your switch statements magical
struct CustomMatcher<Value> {
let closure: (Value) -> Bool
static func ~= (caseValue: CustomMatcher<Value>, switchValue: Value) -> Bool {
caseValue.closure(switchValue)
}
static func ~= (caseValue: Value, switchValue: CustomMatcher<Value>) -> Bool {
switchValue.closure(caseValue)
}
}
import Foundation
protocol TransformerType {
associatedtype BaseType
associatedtype TypeForCoding: Codable
static var encodeTransform: (BaseType) throws -> TypeForCoding { get }
static var decodeTransform: (TypeForCoding) throws -> BaseType { get }
}
@propertyWrapper
@AliSoftware
AliSoftware / RegEx.swift
Created July 31, 2019 13:46
Simple wrapper around NSRegularExpression to provide a swiftier API and, ability to have matches exposing Range instead of NSRange
// Simple wrapper around NSRegularExpression to provide a swiftier API and, ability to have matches exposing Range instead of NSRange
import Foundation
struct RegEx {
let regex: NSRegularExpression
init(pattern: String, options: NSRegularExpression.Options = []) throws {
self.regex = try NSRegularExpression(pattern: pattern, options: options)
}