Skip to content

Instantly share code, notes, and snippets.

int
binary_search_first_position(int *A, int n, int target) {
int end[2] = { -1, n };
while (end[0] + 1 < end[1]) {
int mid = (end[0] + end[1]) / 2;
int sign = (unsigned)(A[mid] - target) >> 31;
end[1-sign] = mid;
}
int high = end[1];
if (high >= n || A[high] != target)
@ajdiaz
ajdiaz / python-supervise.py
Created October 2, 2010 14:23
python snippet to handle runit/daemontools services
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
"""
Python supervise
----------------
This module provide a methods to handle runit [1]_ or daemontools [2]_ based
supervised services, using the control file provided. Here are a small
example::