Skip to content

Instantly share code, notes, and snippets.

// Copyright (c) 2019–20 Adam Sharp and thoughtbot, inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@adamtaylor
adamtaylor / archive-old-branches.pl
Last active October 4, 2019 23:36
Script to archive branches older than two years
#!perl
use strict;
use warnings;
use feature 'say';
use DateTime;
use DateTime::Format::ISO8601;
# Very crude argument handling/safety check
say "Usage: $0 for_real # really perform actions";
@steipete
steipete / gist:8c683dd840596e34dcb9159373cea933
Created November 8, 2017 23:33
NSObject is overloaded. This is iOS 11.2b2. Crazy. And yes, `pspdf` is guilty as well. It's so easy/convenient to make a category on it.
Class Methods:
+ (Class) safeCategoryBaseClass; (0x12c470134)
+ (BOOL) _old_unswizzled_automaticallyNotifiesObserversForKey:(id)arg1; (0x1150df5a0)
+ (id) _old_unswizzled_keyPathsForValuesAffectingValueForKey:(id)arg1; (0x1150df620)
+ (id) requiredStoreLibraryPersonalizationProperties; (0x118daaeff)
+ (void) mf_clearLocks; (0x11a41d09e)
+ (void) _accessibilityCalDetailStringForEvent:(id)arg1 inLine1:(id*)arg2 inLine2:(id*)arg3 inLine3:(id*)arg4 inLine4:(id*)arg5; (0x127db7c6e)
+ (void) _accessibilityCalGetHourDesignatorsForAM:(id*)arg1 andPM:(id*)arg2; (0x127d1e7bb)
+ (BOOL) _accessibilityCalSpaceBetweenDesignatorsAndHour; (0x127d1e7cb)
+ (BOOL) _accessibilityCalHourDesignatorsAreBeforeHour; (0x127d1e7ec)
@mbuchetics
mbuchetics / json.swift
Created June 30, 2017 09:28 — forked from reckenrode/json.swift
Decoding arbitrary JSON with the new Decoder in Swift 4
enum JSON: Decodable {
case bool(Bool)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
init(from decoder: Decoder) throws {
if let container = try? decoder.container(keyedBy: JSONCodingKeys.self) {
self = JSON(from: container)
@reckenrode
reckenrode / json.swift
Created June 23, 2017 14:25
Decoding arbitrary JSON with the new Decoder in Swift 4
enum JSON: Decodable {
case bool(Bool)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
init(from decoder: Decoder) throws {
if let container = try? decoder.container(keyedBy: JSONCodingKeys.self) {
self = JSON(from: container)
import Foundation
import UIKit
// Usage Examples
let shadowColor = Color.shadow.value
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5)
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value
enum Color {
@emaloney
emaloney / guard-closure.md
Last active August 1, 2023 00:24
A simplified notation for avoiding the weak/strong dance with closure capture lists

Simplified notation for avoiding the [weak self]/strongSelf dance with closures

  • Proposal: TBD
  • Author: Evan Maloney
  • Status: Draft
  • Review manager: TBD

Introduction

Frequently, closures are used as completion callbacks for asynchronous operations, such as when dealing with network requests. It is quite common to model these sorts of operations in such a way that an object instance represents a request/response transaction, for example:

@amitpdev
amitpdev / adjust_gpx_to_apple_format.awk
Created September 16, 2015 17:17
Use this awk script to adjust standard GPX files downloaded from any site (bikes) into a GPX format that is supported by Xcode.
awk '
BEGIN {
buffer=""
}
{
gsub(/<\/*trk>/,"",$0)
gsub(/<\/*trkseg>/,"",$0)
gsub(/<trkpt/,"<wpt", $0)
gsub(/<\/trkpt>/,"<\/wpt>", $0)
print
@troystribling
troystribling / ProtocolAssociatedType.swift
Last active April 28, 2022 20:55
A swift protocol with associated type used as type parameter in generic function
protocol Thing {
typealias argType
func doit(val:argType) -> argType
}
class IntThing : Thing {
func doit(val: Int) -> Int {
return val + 1
}
}