Skip to content

Instantly share code, notes, and snippets.

module maid;
import tools.base, tools.functional, irc, dice: rand;
// returns randomized indices of maxcount top values
int[] SelectTopRand(int[] input, int count) {
if (!input.length) return null;
if (input.length == 1) return [0];
int max = input[1], maxpos;
foreach (i, v; input) if (v > max) { max = v; maxpos = i; }
module restarter;
import std.string, std.file, std.thread, std.time, std.fun;
extern(C) {
alias pid_t = int;
pid_t fork();
int execv(char* path, char** argv);
pid_t waitpid(pid_t, int* status, int options);
}
module bintest;
// assume array is sorted from small to big
int findIndexOfOne(int[] array, int value) {
if (!array.length) raise new Error "$value not found during binsearch";
auto test-idx = array.length / 2;
if (array[test-idx] == value) return test-idx;
if (array[test-idx] < value) // everything before test-idx is also smaller
return findIndexOfOne(array[test-idx+1 .. $], value) + test-idx+1;
else // everything after test-idx is also larger
@FeepingCreature
FeepingCreature / gist:2829381
Created May 29, 2012 16:26
bintest with success
module bintest;
// assume array is sorted from small to big
int findIndexOfOne(int[] array, int value) {
if (!array.length) raise new Error "$value not found during binsearch";
auto test-idx = array.length / 2;
if (array[test-idx] == value) return test-idx;
if (array[test-idx] < value) // everything before test-idx is also smaller
return findIndexOfOne(array[test-idx+1 .. $], value) + test-idx+1;
else // everything after test-idx is also larger
module restarter;
import std.string, std.file, std.thread, std.time, std.fun;
extern(C) {
alias pid_t = int;
pid_t fork();
int execv(char* path, char** argv);
pid_t waitpid(pid_t, int* status, int options);
}
string host;
string nick = "neatbot";
string channel;
using new Options {
addLong("host", "h", \(string h) { host = h; }, =>required);
addLong("nick", "n", \(string n) { nick = n; });
addLong("channel", "c", \(string c) { channel = c; }, =>required);
args = process args;
}
auto sock = connect (host, 6667);
+ public int getSelectedSlotId()
+ {
+ if (!mod_ComputerCraft.isMultiplayerClient()) {
+ synchronized (this.m_inventory) {
+ ItemStack itemstack = this.m_inventory[this.m_state.selectedSlot];
+ if (itemstack == null) return -1;
+ return itemstack.id;
+ }
+ }
+
WorldObject[auto~] inRect(vec2f a, b) {
auto world-center = vec3f(0), world-radius = 1;
auto center = cam.apply(world-center).xy;
float radius;
using glModelviewMatrix {
cam.unrotate;
auto offset = cam.apply(world-center + world-radius * vec3f.X).xy - center;
radius = |offset|;
}
auto aspect = vec2f(1, 1/cam.aspect);