Skip to content

Instantly share code, notes, and snippets.

@alemar11
alemar11 / RandomNumbers.swift
Created April 20, 2017 20:08 — forked from jstn/RandomNumbers.swift
generate random numbers for 64-bit types while mitigating modulo bias
/*
`arc4random_uniform` is very useful but limited to `UInt32`.
This defines a generic version of `arc4random` for any type
expressible by an integer literal, and extends some numeric
types with a `random` method that mitigates for modulo bias
in the same manner as `arc4random`.
`lower` is inclusive and `upper` is exclusive, thus:
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@alemar11
alemar11 / lenses-and-prisms-in-swift-a-pragmatic-approach.swift
Created May 17, 2017 07:30 — forked from broomburgo/lenses-and-prisms-in-swift-a-pragmatic-approach.swift
code for the article "Lenses and Prisms in Swift: a pragmatic approach"
/// source: https://broomburgo.github.io/fun-ios/post/lenses-and-prisms-in-swift-a-pragmatic-approach/
protocol LensType {
associatedtype WholeType
associatedtype PartType
var get: (WholeType) -> PartType { get }
var set: (PartType,WholeType) -> WholeType { get }
init(get: @escaping (WholeType) -> PartType, set: @escaping (PartType,WholeType) -> WholeType)
@alemar11
alemar11 / MultiDirectionAdjudicatingScrollView.swift
Created July 15, 2017 08:33 — forked from andymatuschak/MultiDirectionAdjudicatingScrollView.swift
Source for the Khan Academy app's unusual scrolling interactions
//
// MultiDirectionAdjudicatingScrollView.swift
// Khan Academy
//
// Created by Andy Matuschak on 12/16/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
import UIKit.UIGestureRecognizerSubclass
@alemar11
alemar11 / async-operation.swift
Created August 4, 2017 15:25 — forked from pgherveou/async-operation.swift
Async operationQueue
import Foundation
/// List of states that can be used to update an asynchronous operation state.
public enum AsyncOperationState {
case ready
case executing
case finished
fileprivate var keyPath: String {
switch self {
@alemar11
alemar11 / CustomFontMetrics.swift
Created September 5, 2017 13:32 — forked from zwaldowski/CustomFontMetrics.swift
[WIP] UIFontMetrics Backport from iOS 11
//
// CustomFontMetrics.swift
//
// Created by Zachary Waldowski on 6/6/17.
// Licensed under MIT.
//
import UIKit
private extension UITraitCollection {
@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