Skip to content

Instantly share code, notes, and snippets.

View memfrag's full-sized avatar

Martin Johannesson memfrag

View GitHub Profile
import Cocoa
enum Animal {
case aardvark(NSWindow.StyleMask)
case bear
case cat
}
func isNotCat(_ animal: Animal) -> Bool {
switch animal {
@memfrag
memfrag / .swiftlint.yml
Created February 17, 2019 20:01
SwiftLint rules
whitelist_rules: # only these rules will be applied
- line_length
- file_length
- function_body_length
- type_body_length
- type_name
- identifier_name
- class_delegate_protocol
- weak_delegate
- anyobject_protocol
import Foundation
private class Nothing: Decodable { }
func decodeArray<T, U: Decodable>(_ container: KeyedDecodingContainer<T>, forKey key: T) throws -> [U] {
var unkeyedContainer = try container.nestedUnkeyedContainer(forKey: key)
var objects: [U] = []
while !unkeyedContainer.isAtEnd {
do {
let object = try unkeyedContainer.decode(U.self)
@memfrag
memfrag / IDETemplateMacros.plist
Last active August 26, 2017 12:55
Put file in ~/Library/Developer/Xcode/UserData or <Project>.xcodeproj/xcshareddata/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
// ___COPYRIGHT___
//</string>
</dict>
</plist>
@memfrag
memfrag / .gitignore
Created April 8, 2017 09:43
.gitignore
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
import Foundation
import Compression
/// A convenience class for compressing an NSData object.
///
/// Example:
/// ```
/// let compression = Compression(algorithm: .ZLIB)
/// let compressedData = compression.compressData(data)
/// let decompressedData = compresison.decompressData(compressedData)
@memfrag
memfrag / NumberStrings.swift
Created October 10, 2015 08:48
Array of number strings
let numberStrings = (1...10).map(String.init)
@memfrag
memfrag / MJPlaceholderView.h
Last active August 29, 2015 14:14
Interface Builder Designable Custom View
#import <UIKit/UIKit.h>
// IB_DESIGNABLE means that the view will be
// rendered live in Interface Builder.
IB_DESIGNABLE
@interface MJPlaceholderView : UIView
// IBInspectable means that the property
@memfrag
memfrag / FilterMapReduce.swift
Last active February 8, 2019 08:40
[Swift] Example of filter, map, and reduce
enum Faction {
case empire
case rebels
}
let characters: [(name: String, faction: Faction, episodes: [Int])] = [
(name: "Darth Maul", faction: .empire, episodes: [1]),
(name: "Han Solo", faction: .rebels, episodes: [4, 5, 6]),
(name: "Palpatine", faction: .empire, episodes: [1, 2, 3, 5, 6]),
(name: "R2-D2", faction: .rebels, episodes: [1, 2, 3, 4, 5, 6]),
@memfrag
memfrag / BiggestValue.swift
Last active August 29, 2015 14:04
[Swift] Biggest Value of a Sequence of Numbers
let values: [UInt] = [4, 8, 15, 16, 23, 42]
let biggestValue = values.reduce(0, {$1 > $0 ? $1 : $0})
// biggestValue is now 42