Author: Chris Lattner
// Playground - noun: a place where people can play | |
import UIKit | |
import CoreGraphics | |
public enum Result<T> { | |
case Success(@autoclosure () -> T) | |
case Failure(String) | |
init(_ value:T) { |
function mapValues(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
result[key] = fn(obj[key], key); | |
return result; | |
}, {}); | |
} | |
function pick(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
if (fn(obj[key])) { |
import Foundation | |
// | |
// MARK: - JSONError Type | |
// | |
public enum JSONError: ErrorType, CustomStringConvertible { | |
case KeyNotFound(key: JSONKeyType) | |
case NullValue(key: JSONKeyType) | |
case TypeMismatch(expected: Any, actual: Any) |
public extension CustomDebugStringConvertible { | |
var debugDescription: String { | |
return debugDescription() | |
} | |
func debugDescription(_ indentationLevel: Int = 0, includeType: Bool = true) -> String { | |
let indentString = (0..<indentationLevel).reduce("") { tabs, _ in tabs + "\t" } | |
var s: String |
defmodule MyApp.Scheduler do | |
@moduledoc """ | |
Schedules a Mix task to be run at a given interval in milliseconds. | |
## Options | |
- `:task`: The name of the Mix task to run. | |
- `:args`: A list of arguments to pass to the Mix task's `run/1` function. | |
- `:interval`: The time interval in millisconds to rerun the task. |
// | |
// Actor.Swift | |
// | |
// Copyright (c) 2017 Robert Brown | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is |
def get_ipv4_address() do | |
:inet.getifaddrs() | |
|> elem(1) | |
|> Enum.find(fn {_interface, attr} -> | |
case attr |> Keyword.get_values(:addr) do | |
[] -> false | |
list -> list |> Enum.find(fn(addr) -> | |
case addr do | |
nil -> false | |
{127, 0, 0, 1} -> false |
The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).
My take-aways are:
-
You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.
-
Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse