Last active
February 9, 2016 14:47
-
-
Save xentec/f8f3df9d5b638a6b0b7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Return the number of running processes of the system */ | |
ulong getProcNum() | |
{ | |
version(linux) | |
{ | |
import std.file, std.algorithm, std.ascii; | |
return "/proc".dirEntries(SpanMode.shallow).count!(a => a.name.baseName.all!isDigit); | |
} | |
} | |
/* Determine the closest element in _arr_ to _n_ */ | |
Number closest | |
(Number) | |
(in Number[] arr, Number n) | |
@safe pure @nogc nothrow | |
{ | |
import std.math: abs; | |
size_t h = arr.length / 2; | |
return h ? n.closest(abs(n-arr[h-1]) < abs(n-arr[h]) ? arr[0..h] : arr[h..$]) : arr[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment