Skip to content

Instantly share code, notes, and snippets.

@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);
(last
(set-orbit-cam (vec3f 3.837126 7.379855 -4.791716) (vec3f 3.500207 0.000000 0.411292) 30.000000)
(last (set world (new-world))
(let (s
(last (set sun (new-sun))
(set (: sun 'red 'points)(concat (concat (concat (concat (array (vec2f 0.000000 0.629209)) (array (vec2f 0.163556 0.826542))) (array (vec2f 0.412838 0.842308))) (array (vec2f 0.757921 1.000000))) (array (vec2f 1.000000 1.000000))))
(set (: sun 'green 'points)(concat (concat (concat (concat (array (vec2f 0.000000 0.000000)) (array (vec2f 0.291183 0.228994))) (array (vec2f 0.796009 0.713471))) (array (vec2f 0.887297 0.906324))) (array (vec2f 1.000000 1.000000))))
(set (: sun 'blue 'points)(concat (concat (concat (concat (array (vec2f 0.000000 0.000000)) (array (vec2f 0.677794 0.170746))) (array (vec2f 0.860412 0.713225))) (array (vec2f 0.905171 0.864973))) (array (vec2f 1.000000 1.000000))))
sun)
) ((: world 'add) s))
module test;
template S(T) { struct S { alias P = T; alias ToInt = value-of!T.ToInt + 1; } }
struct Z { alias ToInt = 0; }
template ToType(alias T) {
static if (T > 0) { alias ToType=S!ToType!(T-1); }
else { alias ToType=Z; }
}
template Func2(T) {
alias Func2 = T[2] function(T[0], T[1]);
}
module test;
template S(T) { struct S { alias P = T; alias ToInt = value-of!T.ToInt + 1; } }
struct Z { alias ToInt = 0; }
template ToType(alias T) {
static if (T > 0) { alias ToType=S!ToType!(T-1); }
else { alias ToType=Z; }
}
template Func2(T) {
alias Func2 = T[2] function(T[0], T[1]);
}