Skip to content

Instantly share code, notes, and snippets.

View AliSoftware's full-sized avatar

Olivier Halligon AliSoftware

View GitHub Profile
//#! Swift 5
import Foundation
import AppKit
////////////////////////////////////////////////////////////////////
//: ## Type Definition
struct AttrString {
let attributedString: NSAttributedString
@AliSoftware
AliSoftware / JSON-Rounding-Behavior.swift
Created August 21, 2018 17:29
JSON Rounding Behavior
func json(from dict: [String: Any]) -> String {
let jsonData = try! JSONSerialization.data(withJSONObject: dict, options: [])
let str = String(data: jsonData, encoding: .utf8)!
return str
}
struct Product {
var price: Double
var quantity: Int
@AliSoftware
AliSoftware / Coordinators-v2.swift
Last active May 4, 2023 12:26
Our implementation of the Coordinators pattern — V2, more strict than V1
// Coordinator.swift
import Foundation
public protocol Coordinator: class {
var components: CoordinatorComponents { get }
/// Set up here everything that needs to happen just before the Coordinator is presented
///
/// - Parameter modalSetup: A parameter you can use to customize the default mainViewController's
@AliSoftware
AliSoftware / launch_ipa.sh
Last active August 4, 2023 00:13
Script to install & launch an iOS build (for iphonesimulator platform) into an iOS Simulator. Especially useful for Fabric needing a first launch to upload
#!/bin/bash
#->Usage: launch_ipa.sh <PATH.app> [DEVICE_TYPE] [IOS_RUNTIME]
#->
#-> Create a new simulator, install the app in it, launch it, wait 20s then kill it.
#-> The main purpose of this script is to just launch an app and let the applicationDidFinishLaunching… callback be called
#->
#-> - [DEVICE_TYPE] the model of simulator to use. See `xcrun simctl list devicetypes` for the full list. Defaults to 'iPhone-6s'
#-> Note: You just need to provide the last part of the full device ID from
#-> com.apple.CoreSimulator.SimDeviceType.<DEVICE_TYPE>
@AliSoftware
AliSoftware / SwiftCopying.swift
Last active August 18, 2021 19:41
TypeSafe copy()/mutableCopy() (NSCopying/NSMutableCopying) in Swift
import Foundation
//: Swift type-safe protocol versions of (Mutable)Copying
protocol SwiftCopying {
associatedtype NonMutableType = Self
func clone() -> NonMutableType
}
extension SwiftCopying where Self: NSCopying {
func clone() -> NonMutableType {
return self.copy() as! NonMutableType
@AliSoftware
AliSoftware / morphing.swift
Created August 3, 2017 13:07
A simple demo of doing some morphing using CAShapeLayer & UIBezierPath
import UIKit
import PlaygroundSupport
// Create a view to display the result in playground
let view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
view.backgroundColor = .white
PlaygroundPage.current.liveView = view;
@AliSoftware
AliSoftware / git-gerrit
Last active August 30, 2018 21:37
A "git squash" command to squash multiple commits into one automatically
#!/bin/bash
#####
#
# git-gerrit v1.1
# O. Halligon, 2017.08.18
#
#####
#
# Usage:
#
@AliSoftware
AliSoftware / keywords.md
Last active June 5, 2017 00:02
Introducing Role Keywords to Protocol Implementations

Introducing Role Keywords to Protocol Implementations to Reduce Code Errors

Introduction

This proposal enhances protocol safety at compile time by incorporating role keywords to discourage two categories of potential user errors. This proposal can be phased in first over time and language release.

@AliSoftware
AliSoftware / README-UIKonf17-Talk.md
Last active May 17, 2017 20:46
UIKonf talk - CodeGeneration in Swift - Links & Snippets

This is a reference of all the useful links to follow my UIKonf'17 talk on Code Generation in Swift

@AliSoftware
AliSoftware / GHDiff-HidePods.js
Last active February 13, 2017 11:40
Hide Pods/* related files in a GitHub diff page
// When you are in the diff page of a GitHub PR
// And want to hide all the Pods/* files in that diff page, use this:
// Paste that in your Web Inspector's console
var nodes = document.evaluate("//div[@class='file-header' and starts-with(@data-path,'Pods/')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
for(i=0; i<nodes.snapshotLength; ++i) {
nodes.snapshotItem(i).parentNode.hidden = true
}
// Or even better, create a bookmark with this code for easy quick access: