Skip to content

Instantly share code, notes, and snippets.

@Leehro
Leehro / semaphore.m
Created October 30, 2013 19:18
I love this. Use a dispatch_semaphore_t to limit how many blocks you dispatch to a queue.
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
// Then in some loop ...
if(dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) == 0) {
dispatch_async(queue, ^{
// Some code that needs to run but doesn't need to fill up the queue.
//
dispatch_semaphore_signal(semaphore);
});
@Leehro
Leehro / index.html
Created March 28, 2013 14:57
Simple d3bugging
<!DOCTYPE html>
<meta charset="utf-8">
<style></style>
<body>
<div id="bar-demo"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
// now moving onto books read per year
// set up an array of the data