Skip to content

Instantly share code, notes, and snippets.

View memfrag's full-sized avatar

Martin Johannesson memfrag

View GitHub Profile
@memfrag
memfrag / SquaredOperator.swift
Last active August 29, 2015 14:04
[Swift] Custom Assignment Operator
operator infix <- {}
infix func <- <T>(inout left: T, right: T) {
left = right
}
var value = 0 // Initialize
value <- 1337
// value now contains 1337
@memfrag
memfrag / SquaredOperator.swift
Last active August 29, 2015 14:04
[Swift] Squared Operator
operator postfix ** {}
postfix func ** (value: Int) -> Int {
return value * value
}
let a = 3** + 1
// a now contains 10
@memfrag
memfrag / SwapOperator.swift
Last active August 29, 2015 14:04
[Swift] Swap Operator
operator infix <=> {}
infix func <=> <T>(inout left: T, inout right: T) {
let tmp = left
left = right
right = tmp
}
var a = 1337
var b = 4711
@memfrag
memfrag / MeanValue.swift
Last active August 29, 2015 14:04
[Swift] Mean Value of a Sequence of Numbers
let values = [4, 8, 15, 16, 23, 42]
let meanValue = values.reduce(0, +) / values.count
// + is a operator function and we can pass it in to reduce as the function parameter.
@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
@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 / NumberStrings.swift
Created October 10, 2015 08:48
Array of number strings
let numberStrings = (1...10).map(String.init)
@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 / .gitignore
Created April 8, 2017 09:43
.gitignore
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
@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>