Skip to content

Instantly share code, notes, and snippets.

View AliSoftware's full-sized avatar

Olivier Halligon AliSoftware

View GitHub Profile
@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:
@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 / 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 / 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 / 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 / FailableDecode.swift
Last active January 24, 2019 14:15
Decode an array of objects, allowing some of the items to fail without stopping the decoding of the rest
import Foundation
//: ## Option 1: A Failable type for each item
//: In practice, it's very similar to the concept of the "Result" type that you see in most code bases (and that will be integrated in Swift 5), so if you already have a Result type, you might just want to use it instead, but if not, this is a super-simplification of it
enum Failable<T>: CustomStringConvertible {
case success(T)
case failure(Error)
var description: String {
@AliSoftware
AliSoftware / lint_snippets_in_markdown.rb
Last active February 9, 2019 16:52
Runs SwiftLint on all code snippets found in a markdown file
#!/usr/bin/env ruby
require 'tmpdir'
require 'open3'
# The first parameter is supposed to be the path to the markdown file
input_file = ARGV.first
config_file = ARGV[1] || '.swiftlint.yml'
config_param = File.exist?(config_file) ? " --config #{File.realpath(config_file)}" : ''
@AliSoftware
AliSoftware / Dangerfile-build_settings.rb
Last active February 14, 2019 14:27
Dangerfile Rules
#######################################
# Check that some Build Settings (those defined by VERSION_SETTINGS below) are set on the right level (target/project)
#######################################
VERSION_SETTINGS = %w(GLOBAL_APP_VERSION GLOBAL_APP_BUILD_VERSION)
require 'xcodeproj'
project = Xcodeproj::Project.open('YOUR_PROJECT_NAME.xcodeproj')
target = project.targets.find("YOUR_TARGET_NAME").first
target.build_configurations.each do |bc|
## Don't allow some build settings at target level (but only at project level)
@AliSoftware
AliSoftware / xcodeproj_check_files_in_proper_targets.rb
Last active May 2, 2019 13:12
This script walks thru all the files in a Xcode project's groups belong to the target they are supposed to, according to group names found while walking the groups hierarchy.
#!/usr/bin/env ruby
# This script walks thru all the files in a Xcode project's groups belong to the target they are supposed to
# according to group names found while walking the groups hierarchy.
#
# This example only focuses on test files and groups/targets ending with "...Tests"
require 'xcodeproj'
def check(group, all_targets, walk_path, ctx_target_name = nil, ctx_expected_files_list = nil)
//#! Swift 5
import Foundation
import AppKit
////////////////////////////////////////////////////////////////////
//: ## Type Definition
struct AttrString {
let attributedString: NSAttributedString