Skip to content

Instantly share code, notes, and snippets.

Avatar

Pierre Felgines felginep

View GitHub Profile
View LayoutConstraint.swift
struct ConstraintBuilder {
var firstItem: UIView?
var firstAttribute: NSLayoutAttribute?
var relation: NSLayoutRelation?
var secondAttribute: NSLayoutAttribute?
var secondItem: UIView?
var multiplier: CGFloat = 1.0
var constant: CGFloat = 0.0
}
View gist:9c47820333603635aa3643966afc2594

Xcode Shortcuts

Customized

^& Standard Editor > Show Related Items ^1
Standard Editor > Show Previous History ^2
^⌘É Standard Editor > Show Previous File History ^⌘2
^" Standard Editor > Show Next History ^3
^⌘" Standard Editor > Show Next Files History ^⌘3
^’ Standard Editor > Show Top Level Items ^4
View ContentSize.swift
protocol ContentSizable {
func ad_updateContentSize()
}
extension UIView : ContentSizable {
func ad_updateContentSize() {
subviews.forEach { $0.ad_updateContentSize() }
}
}
View .swiftlint.yml
disabled_rules: # rule identifiers to exclude from running
# not sure
- closure_parameter_position
- unused_closure_parameter
- operator_whitespace # what about defining func ==()
- colon
# - force_cast
# - force_try
# useless
View AlertBuilder.swift
import UIKit
struct AlertBuilder {
private var style: UIAlertController.Style = .alert
private var title: String?
private var message: String?
private var actions: [UIAlertAction] = []
func style(_ style: UIAlertController.Style) -> AlertBuilder {
View alert-function-builder.swift
import UIKit
struct Action {
let title: String
let style: UIAlertAction.Style
let action: () -> Void
}
extension Action {
static func `default`(_ title: String, action: @escaping () -> Void) -> [Action] {
View PromisePlayground.swift
import UIKit
import Foundation
func test(named: String,
_ work: (_ assert: @escaping (Bool) -> Void, _ done: @escaping () -> Void) -> Void) {
var testPass = true
var assertCount = 0
let assert: (Bool) -> Void = { value in
assertCount = assertCount + 1
testPass = testPass && value
@felginep
felginep / comment_github_issue.rb
Created Aug 7, 2020
Fastlane action to comment a Github issue / pull request
View comment_github_issue.rb
# heavily inspired from https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/set_github_release.rb
module Fastlane
module Actions
module SharedValues
COMMENT_GITHUB_ISSUE_COMMENT_LINK = :COMMENT_GITHUB_ISSUE_COMMENT_LINK
COMMENT_GITHUB_ISSUE_COMMENT_ID = :COMMENT_GITHUB_ISSUE_COMMENT_ID
COMMENT_GITHUB_ISSUE_COMMENT_JSON = :COMMENT_GITHUB_ISSUE_COMMENT_JSON
end
class CommentGithubIssueAction < Action
@felginep
felginep / Fastfile.rb
Last active Aug 10, 2020
Automatically post a PR comment if a license warning is found
View Fastfile.rb
lane :lint_pull_request do |options|
add_license_message(
repository_name: "felginep/my-ios-app",
api_token: ENV["GITHUB_TOKEN"],
issue_number: options[:issue_number]
)
end
@felginep
felginep / RequiredOptions.rb
Created Oct 7, 2020
Create lanes with non optional parameters and raises an error if we try to access a missing value from the `option` hash
View RequiredOptions.rb
class Fastlane::FastFile # from https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/fast_file.rb
# Hash that raises an error when we access a missing value
class RequiredOptions < Hash
def initialize(options, lane)
options.each { |key, value| self[key] = value }
@lane = lane
end
You can’t perform that action at this time.