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
@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]),
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)
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 / HelloWorld.swift
Last active November 12, 2017 02:18
[Swift] Running Swift #! Scripts
#!/usr/bin/xcrun swift
println("Hello, World!")
@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
@memfrag
memfrag / syscon.c
Last active December 14, 2015 11:09
syscon - A tool for reading the system console from an iOS device via USB and displaying it in the OS X terminal in "real time".
/*
* syscon - A tool for reading the system console from an iOS device
* via USB and displaying it in the OS X terminal in "real time".
*
* This tool and its source code is hereby released into the public domain.
* No warranty given, no responsibility taken. Use at your own risk.
*
* How to build:
*
* clang -o syscon -framework CoreFoundation -framework MobileDevice
@memfrag
memfrag / NumberStrings.swift
Created October 10, 2015 08:48
Array of number strings
let numberStrings = (1...10).map(String.init)