Skip to content

Instantly share code, notes, and snippets.

View daurnimator's full-sized avatar

daurnimator

View GitHub Profile
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 16, 2024 01:02
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

@katlogic
katlogic / poll.c
Created September 18, 2016 00:48
#include <sys/epoll.h>
#include <sys/socket.h>
#include <stdio.h>
int main()
{
struct epoll_event ev = {
.data.fd = 1
};
int efd = epoll_create(1);
ev.events = EPOLLIN|EPOLLET;
@a-dma
a-dma / yubitouch.sh
Last active March 10, 2022 14:43
Bash script for setting or clearing touch requirements for cryptographic operations in the OpenPGP application on a YubiKey 4.
#!/bin/bash
# Bash script for setting or clearing touch requirements for
# cryptographic operations the OpenPGP application on a YubiKey 4.
#
# Author: Alessio Di Mauro <alessio@yubico.com>
GCA=$(which gpg-connect-agent)
DO=0
UIF=0
@daurnimator
daurnimator / dirmngr.conf
Last active July 14, 2021 08:24
My GPG config
hkp-cacert ~/.gnupg/sks-keyservers.netCA.pem
@lukego
lukego / 0readme.md
Created August 16, 2015 16:25
Performance counter access with inline assembler in Lua
@jhass
jhass / .gitignore
Last active July 24, 2022 23:15
powerdns remote backend for hashbang.sh
python/
*.log
@daurnimator
daurnimator / afd.c
Created March 29, 2015 13:28
windows low level polling. compile with: cl /EHsc /Wall /WX main.c afd.c
#pragma warning(push, 3)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <Winternl.h>
#pragma comment(lib, "Ntdll.lib")
#pragma warning(pop)
#include "afd.h"
@daurnimator
daurnimator / gist:a61d223df1f83da8b72a
Created March 14, 2015 21:05
TamperMonkey script - Better dimensions for Glowing Bear
// ==UserScript==
// @name Better dimensions for Glowing Bear
// @namespace http://daurnimator.com
// @version 0.1
// @description Glowing Bear sidebar dimensions
// @author Daurnimator
// @match http://www.glowing-bear.org/
// @grant GM_addStyle
// ==/UserScript==
@daurnimator
daurnimator / sandbox.lua
Last active April 5, 2016 12:56
Sandbox using ljsyscall
local ffi = require "ffi"
local S = require "syscall"
local c = S.c
local t = S.types.t
local util = S.util
local nr = require "syscall.linux.nr"
local lfs = require "syscall.lfs"
-- Returns an iterator over open fds
local function open_fds(pid)
@insin
insin / srsly.js
Last active August 29, 2015 14:01
function new_(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) {
switch (arguments.length) {
case 0: return new this
case 1: return new this(a)
case 2: return new this(a, b)
case 3: return new this(a, b, c)
case 4: return new this(a, b, c, d)
case 5: return new this(a, b, c, d, e)
case 6: return new this(a, b, c, d, e, f)
case 7: return new this(a, b, c, d, e, f, g)