Skip to content

Instantly share code, notes, and snippets.

View cbarrett's full-sized avatar
🏴
Revolting

Colin Barrett cbarrett

🏴
Revolting
View GitHub Profile
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
Making efficient use of the libdispatch (GCD)

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

@Bradshaw
Bradshaw / better_sin.js
Created June 28, 2017 08:47
Better version of Math.sin for javascript
var old_sin = Math.sin;
Math.sin = function(x) {
if (typeof x == "number" && isFinite(x)){
return old_sin(x);
}
var str = "" + x;
if (str.length>0){
str = str.repeat(Math.ceil(Math.max(1,18/str.length)));
}
var sinstr = "|\n";
@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@lukexi
lukexi / Windows 10 Haskell Devbox Setup.md
Last active November 26, 2017 09:24
Windows 10 Haskell Devbox Setup
@leque
leque / freeap.ml
Last active November 25, 2018 09:22
Free Applicative Functors in OCaml
open Higher
(*
See `Free Applicative Functors' http://arxiv.org/abs/1403.0749
*)
type (_, _) t =
| Pure : 'a -> ('a, 'f) t
| Apply : ('a -> 'b, 'f) t * ('a, 'f) app -> ('b, 'f) t
let pure v = Pure v
@powerman
powerman / AsciidocCheatsheet.adoc
Last active March 22, 2024 19:18
Asciidoc cheatsheet for GitHub

Asciidoc cheatsheet for GitHub

@tjw
tjw / PackageSystemHeaders
Created February 25, 2011 00:40
Go beyond the release notes!
#!/bin/zsh -f
set -e
PKG_DIR=/tmp/SystemHeaders-`uname -r`
echo "Packaging $PKG_DIR..."
mkdir -p $PKG_DIR
cd /
for d in System/Library/Frameworks usr/include Developer/Library/Frameworks usr/lib; do