Skip to content

Instantly share code, notes, and snippets.

View 4np's full-sized avatar

Jeroen Wesbeek 4np

  • ServiceNow
  • The Netherlands
View GitHub Profile
@4np
4np / UIView+fromNib.swift
Created October 18, 2017 09:30
Swift generics Nib loading
import Foundation
extension UIView {
class func fromNib<T : UIView>() -> T {
//swiftlint:disable:next force_unwrapping
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T
}
}
@4np
4np / performance-methods.md
Created September 25, 2017 08:50
Useful methods related to performance on iOS devices

iOS Performance

A list of methods and functions to use when optimizing your iOS application for performance.

@4np
4np / Xcode8-iOS11.md
Last active September 15, 2017 12:09
Use Xcode 8 with iOS 11 / Xcode 9

Use Xcode 8 with iOS 11

  • Copy or symlink the iPhoneOS.Platform's DeviceSupport into Xcode 8 (guide):
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/11.0\ \(15A5278f\) /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/11.0
  • Make sure you use the right xcode tools:
@4np
4np / createMacOSSierraInstallMedia.md
Last active June 6, 2017 11:53
Create Mac OS Sierra Install Media

Create Mac OS Sierra Install Media

After formatting an USB drive and naming it SierraBootInstall, execute the following line:

sudo /Applications/Install\ macOS\ 10.13\ beta.app/Contents/Resources/createinstallmedia --volume /Volumes/SierraBootInstall --applicationpath /Applications/Install\ macOS\ 10.13\ beta.app --nointeraction &&say Done
@4np
4np / create-json.swift
Created March 10, 2017 13:35
Creating JSON in Swift (Playground)
//: Playground - noun: a place where people can play
import UIKit
//[{
// "508d49e5d7200200b96d45a3ce6103c4":[{ // filter widget id
// "table":"incident",
// "filter":"categoryINsoftware"
// }],
// "id":”508d49e5d7200200b96d45a3ce6103c4” // filter widget id
@4np
4np / loadTest.sh
Created February 1, 2017 10:25
Load Testing
# 100 connections, 10 second duration, 4 threads
wrk -c 100 -d 10 -t 4 http://localhost:8080
@4np
4np / macOSDisplays.swift
Created January 24, 2017 23:34
Access Mac OS Displays
private func getActiveDisplays() -> [CGDirectDisplayID] {
var displayCount: UInt32 = 0
// get the number of active displays
guard CGGetActiveDisplayList(0, nil, &displayCount) == .success else {
return []
}
// get the active displays
let allocated = Int(displayCount)
@4np
4np / ambientLightSensor.swift
Created January 24, 2017 23:33
Acces Mac OS Ambient Light Sensor
func getLux() {
guard let serviceType = IOServiceMatching("AppleLMUController") else {
debugPrint("No ambient light sensor")
return
}
// get and release service
let service = IOServiceGetMatchingService(kIOMasterPortDefault, serviceType)
defer {
IOObjectRelease(service)
@4np
4np / menuBarApplication.md
Last active March 9, 2017 22:15
OS X Menu Bar Application

How to quickly create a menu bar application

Add a status bar icon

Download this icon and drag it into your Assets.xcassets.

Add a status item

AppDelegate.swift

@4np
4np / SwiftyFrameworks.md
Last active December 24, 2018 18:58
Useful Frameworks, most of them developed in Swift

A list of Swifty Frameworks

Below you will find a list of interesting (primarily) Swift frameworks. This not at all a complete list, merely a list of frameworks I like and am thinking of using.

Alamofire

octicon An HTTP networking library written in Swift. Also see the Networking library mentioned below.

pod 'Alamofire', '~&gt; 4.0'