Skip to content

Instantly share code, notes, and snippets.

tclementdev /
Last active Aug 5, 2020
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

entone / get_ip4_address.ex
Last active Oct 3, 2017
iterate over local network interfaces and find first non local ip4v address
View get_ip4_address.ex
def get_ipv4_address() do
|> 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
rob-brown / Actor.swift
Last active Mar 8, 2018
Elixir-inspired concurrency primitives
View Actor.swift
// 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
danielberkompas / scheduler.ex
Created Oct 26, 2016
A simple mix task scheduler for Elixir apps
View scheduler.ex
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.
mcmurrym / MirrorDebugDecscription.swift
Last active Dec 24, 2019
A default protocol implementation for CustomDebugStringConvertible that uses Mirror for introspection
View MirrorDebugDecscription.swift
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
jarsen / JaSON.swift
Last active Nov 10, 2016
JSON Value Extraction in Swift. Blog post here
View JaSON.swift
import Foundation
// MARK: - JSONError Type
public enum JSONError: ErrorType, CustomStringConvertible {
case KeyNotFound(key: JSONKeyType)
case NullValue(key: JSONKeyType)
case TypeMismatch(expected: Any, actual: Any)
gaearon / slim-redux.js
Last active Jul 26, 2020
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
View slim-redux.js
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])) {
View Pipeline.swift
// 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) {
jarsen / json.swift
Last active Aug 29, 2015
Parsing JSON Playground with Result type. Inspired by Haskell, Swiftz, and
View json.swift
// Playground - noun: a place where people can play
import Foundation
infix operator >>- { associativity left precedence 150 } // Bind
infix operator <^> { associativity left } // Functor's fmap (usually <$>)
infix operator <*> { associativity left } // Applicative's apply
public typealias JSON = AnyObject
public typealias JSONObject = Dictionary<String, JSON>
You can’t perform that action at this time.