Skip to content

Instantly share code, notes, and snippets.

View memfrag's full-sized avatar

Martin Johannesson memfrag

View GitHub Profile
@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 / HelloWorld.swift
Last active November 12, 2017 02:18
[Swift] Running Swift #! Scripts
#!/usr/bin/xcrun swift
println("Hello, World!")
@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 / 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 / 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)