Instantly share code, notes, and snippets.

View karabiner.json
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
View idioms.swift
import UIKit
// this one doesn’t require a helper function
var label: UILabel = {
$0.backgroundColor = .blue
$0.text = "This is a playground"
$0.textColor = .white
$0.textAlignment = .center
return $0
View ObjC.h
#import <Foundation/Foundation.h>
@interface ObjC: NSObject
+ (BOOL)catchException:(void(^)(void))tryBlock error:(__autoreleasing NSError **)error;
@end
View ControllerLifecycle.swift
// From https://albertodebortoli.com/2018/03/12/easy-view-controller-unit-testing/
import XCTest
import UIKit
class ControllerLifecycle<T: UIViewController>
{
private lazy var this = type(of: self).self
private var rootWindow: UIWindow?
var rootController: T? {
View Downloader.swift
// I saw this trick in “Do you often forget [weak self], here is a solution”
// https://medium.com/anysuggestion/preventing-memory-leaks-with-swift-compile-time-safety-49b845df4dc6
import UIKit
class ViewController: UIViewController {
// move this variable inside viewDidLoad to see it being released
let downloader = Downloader()
View BouncyButton.swift
// From “Better Strategies Through Types”
// http://www.figure.ink/blog/2018/3/11/better-strategies-through-types
import UIKit
protocol BouncyDelegate {
static func animateBounce(for view: UIView)
}
enum ShakeStrategy: BouncyDelegate
View PackageApplication
#!/usr/bin/perl
#
# PackageApplication
#
# Copyright (c) 2009-2012 Apple Inc. All rights reserved.
#
# Package an iPhone Application into an .ipa wrapper
#
use Pod::Usage;
View Person.m
#import <Foundation/Foundation.h>
#undef X
typedef void (^salute_t)();
@interface Person : NSObject
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) salute_t salute;
View Colors.swift
enum Colors: Int64
{
case black = 0x000000ff
case white = 0xffffffff
func color() -> UIColor
{
let red = CGFloat((self.rawValue >> 24) & 0xff) / 255.0
let green = CGFloat((self.rawValue >> 16) & 0xff) / 255.0
let blue = CGFloat((self.rawValue >> 8) & 0xff) / 255.0
View AppDelegate.swift
import UIKit
import PluggableApplicationDelegate
@UIApplicationMain
class AppDelegate: PluggableApplicationDelegate
{
override var services: [ApplicationService] {
return [
LoggerApplicationService()
]