Skip to content

Instantly share code, notes, and snippets.

View alemar11's full-sized avatar

Alessandro alemar11

View GitHub Profile
@alemar11
alemar11 / Extra Logging for My Great App.mobileconfig
Created September 5, 2017 13:34 — forked from zwaldowski/Extra Logging for My Great App.mobileconfig
Apple Configuration Profile for Logging in iOS 10 and macOS Sierra
<?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">
<!-- iOS 10, macOS Sierra, and friends bring a new logging subsystem that's
supposed to scale from the kernel, up to frameworks, and up to apps. It defaults
to a more regimented, privacy-focused approach that large apps and complex
systems need.
It, along with Activity Tracing introduced in iOS 8 and macOS Yosemite and the
Console app in macOS Sierra, hope to help you graduate from caveman debugging to
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: view.topAnchor),
@alemar11
alemar11 / podforceupdate.sh
Created September 18, 2017 20:07 — forked from mbinna/podforceupdate.sh
Clear CocoaPods cache, re-download and re-install all pods
#!/usr/bin/env bash
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
@alemar11
alemar11 / SimpleNetworkingExample.swift
Created October 7, 2017 10:27 — forked from sharplet/SimpleNetworkingExample.swift
Example Source Code for "A Simple Approach to Thread-Safe Networking in iOS Apps"
import Foundation
import PlaygroundSupport
enum URLResult {
case response(Data, URLResponse)
case error(Error, Data?, URLResponse?)
}
extension URLSession {
@discardableResult
@alemar11
alemar11 / index.js
Created October 28, 2017 11:11 — forked from MoOx/index.js
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
@alemar11
alemar11 / DynamicKey.swift
Created December 4, 2017 15:39 — forked from samwize/DynamicKey.swift
A CodingKey that is dynamic -- it can be any string! Encode/decode with a Dictionary of `[String : Any]` in the model.
/**
```
// Encode a model with properties of type [String : Any]
var propertiesContainer = container.nestedContainer(keyedBy: DynamicKey.self, forKey: .properties)
if let properties = properties {
try propertiesContainer.encodeDynamicKeyValues(withDictionary: properties)
}
```
*/
struct DynamicKey: CodingKey {
import Foundation
// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a
struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
@alemar11
alemar11 / FileHandleTextOutput.swift
Created December 20, 2017 11:03
FileHandleTextOutput
final public class FileHandleTextOutput: TextOutputStream {
/// File path
let path: String
private let fileHandle: FileHandle
public init?(path: String, append: Bool = false) {
let expandedPath = (path as NSString).expandingTildeInPath
guard let file = FileHandle(forWritingAtPath: expandedPath) else { return nil }
fileHandle = file
@alemar11
alemar11 / DisplayLink.swift
Created January 8, 2018 14:01 — forked from CanTheAlmighty/DisplayLink.swift
DisplayLink for OSX
@alemar11
alemar11 / locking.swift
Created January 16, 2018 09:51 — forked from kristopherjohnson/locking.swift
Simple synchronization functions for Swift, wrapping the Cocoa NSLocking classes
import Foundation
/// Protocol for NSLocking objects that also provide tryLock()
public protocol TryLockable: NSLocking {
func tryLock() -> Bool
}
// These Cocoa classes have tryLock()
extension NSLock: TryLockable {}
extension NSRecursiveLock: TryLockable {}