Skip to content

Instantly share code, notes, and snippets.

View nilium's full-sized avatar
🍉
internal screaming intensifies

Noel nilium

🍉
internal screaming intensifies
View GitHub Profile

libdispatch efficiency tips

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

@nilium
nilium / concurrency.go
Last active May 3, 2016 22:41 — forked from kevinburke/concurrency.go
Helping kevinburke
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@nilium
nilium / valid-ipv4.rb
Last active December 20, 2015 07:29 — forked from havenwood/valid-ipv4.rb
module Valid
OCTET_RANGE = (0 .. 255)
def self.ipv4?(address)
octets = address.split '.'
octets.length == 4 && octets.all? { |octet|
octet_i = octet.to_i
(0..255).cover?(octet_i) && octet_i.to_s(10) == octet
}
end
@nilium
nilium / gifkiller.jquery.js
Created August 20, 2012 18:27 — forked from rlemon/Kill It!
GIF KILLER
javascript:$('img').filter(function() { if( this.src.substr(-3).toUpperCase() === 'GIF' ) return this; }).replaceWith('<img src="http://i.imgur.com/vMgrL.png" />');;
@nilium
nilium / rot13.rb
Created August 8, 2012 18:53 — forked from rlemon/gist:3297381
ROT13 in Ruby
['string'].map{|a|a.split('').map{|b|return b if(!/[a-z]/i.match b);c=b[0].ord>=96;k=(b.downcase[0].ord-96+12)%26+1;[k+(c ? 96: 64)].pack 'U*'}.join}.join
RBNodeColor: enum {
black = 0
red = 1
}
RBNode: class <K, V> {
Nut: class {
cracker: Int
init: func(cracker: Int) {
this cracker = cracker
}
bust: func {
cracked *= 5
@nilium
nilium / max.scala
Created February 28, 2014 01:48 — forked from anonymous/gist:9263513
def max(list: List[Int]): Int = list match {
case Nil => throw new NoSuchElementException
case List(x) => x
case x +: tail =>
val rhs = max(tail)
if (x >= rhs) x else rhs
}