Skip to content

Instantly share code, notes, and snippets.

View Hackerpilot's full-sized avatar

Brian Schott Hackerpilot

View GitHub Profile
@Hackerpilot
Hackerpilot / timer.d
Created September 23, 2019 21:52
Timing code
enum timingSetup = q{
import std.datetime.stopwatch : AutoStart, StopWatch;
import std.stdio : writeln;
import std.conv : to;
auto sw = StopWatch(AutoStart.yes);
size_t lastLine = __LINE__;
};
template timingCheckpoint(size_t l)
{
@Hackerpilot
Hackerpilot / mousecolor.sh
Last active July 22, 2019 20:10
Shell script for setting colors on Sensei 310 on Linux
#!/bin/bash
# This was glued together based on research collected here:
# https://github.com/flozz/rivalcfg/pull/43
WHEEL_RED='\x16'
WHEEL_GREEN='\x16'
WHEEL_BLUE='\xff'
LOGO__RED='\x16'
LOGO__GREEN='\x16'
http://www.keyboard-layout-editor.com/##@@=Esc&_x:1%3B&=F1&=F2&=F3&=F4&_x:1.5%3B&=F5&=F6&=F7&=F8&_x:1.5%3B&=F9&=F10&=F11&=F12&_x:3.5%3B&=PrtSc&=Scroll%20Lock&=Pause%0ABreak%3B&@_y:0.5%3B&=~%0A%60&=!%0A1&=%2F@%0A2&=%23%0A3&=$%0A4&=%25%0A5&=%5E%0A6&_x:0.5%3B&=Num%20Lock&=%2F%2F&=*&=-&_x:0.75%3B&=%2F&%0A7&=*%0A8&=(%0A9&=)%0A0&=%2F_%0A-&=+%0A%2F=&_w:2%3B&=Backspace&_x:0.25%3B&=Insert&=Home&=PgUp%3B&@_w:1.5%3B&=Tab&=Q&=W&=E&=R&=T&_x:1%3B&=7%0AHome&=8%0A%E2%86%91&=9%0APgUp&_h:2%3B&=+&_x:0.25%3B&=Y&=U&=I&=O&=P&=%7B%0A%5B&=%7D%0A%5D&_w:1.5%3B&=%7C%0A%5C&_x:0.25%3B&=Delete&=End&=PgDn%3B&@_w:1.75%3B&=Caps%20Lock&=A&=S&=D&=F&=G&_x:0.75%3B&=4%0A%E2%86%90&=5&=6%0A%E2%86%92&_x:1.5%3B&=H&=J&=K&=L&=%2F:%0A%2F%3B&=%22%0A%27&_w:2.25%3B&=Enter%3B&@_w:2.25%3B&=Shift&=Z&=X&=C&=V&=B&_x:0.25%3B&=1%0AEnd&=2%0A%E2%86%93&=3%0APgDn&_h:2%3B&=Enter&_x:1%3B&=N&=M&=%3C%0A,&=%3E%0A.&=%3F%0A%2F%2F&_w:2.75%3B&=Shift&_x:1.25%3B&=%E2%86%91%3B&@_w:1.25%3B&=Ctrl&_w:1.25%3B&=Win&_w:1.25%3B&=Alt&_w:3.5%3B&=&_x:0.25&w:2%3B&=0%0AIns&=.%0ADel&_x:1.25%
@Hackerpilot
Hackerpilot / magic_tree.d
Created May 19, 2016 23:13
Insertion order stable associative storage
import std.container.rbtree;
struct Node
{
int opCmp(ref const Node other) const
{
if (other.key > this.key)
return -1;
if (other.key < this.key)
return 1;
@Hackerpilot
Hackerpilot / router.d
Last active April 18, 2016 23:31
Route an input range to an output range based on function return value
import std.range.primitives : isInputRange, isOutputRange, ElementType;
import std.meta : ApplyLeft, allSatisfy, staticMap;
import std.functional : unaryFun;
import std.traits : Unqual;
/**
* Copy values from an input range to one of several output ranges based
* on a routing function.
*
* The function must return an integer between 0 and the number of outputs.
@Hackerpilot
Hackerpilot / ice.d
Last active April 13, 2016 23:47
crashes the compiler
template StorageAttributes(Store)
{
enum hasInsertMethod = Store.insert;
enum hasFullSlice = Store.init[];
}
struct ValidSparseDataStore(DataT)
{
DataT insert()
{
correctedInsert!(false);
@Hackerpilot
Hackerpilot / stack_buffer.d
Created March 2, 2016 01:59
Stack Buffer
module dparse.stack_buffer;
import std.traits;
// version = debug_stack_allocator)
struct StackBuffer
{
bool put(T)(T t)
{
@Hackerpilot
Hackerpilot / gc.supp
Last active May 1, 2019 09:33
Valgrind suppression file for the D garbage collector
{
GC1
Memcheck:Cond
fun:_D2gc*
}
{
GC2
Memcheck:Value4
fun:_D2gc2gc*
}
@Hackerpilot
Hackerpilot / vector_sort.d
Last active October 12, 2015 23:31
Sort a 128-bit SIMD register with ubyte contents
module vector_sort;
private enum byteSortCode = `asm
{
mov R8, p;
movdqu XMM0, [R8];
mov R9, 0x0607040502030001;
movq XMM14, R9;
mov R9, 0x0e0f0c0d0a0b0809;
@Hackerpilot
Hackerpilot / _mm_ctvtps_pi8.d
Last active September 3, 2015 23:47
_mm_ctvtps_pi8
ubyte[4] _mm_ctvtps_pi8(float[4] input)
{
ubyte[4] result;
size_t a = cast(size_t) input.ptr;
size_t b = cast(size_t) result.ptr;
asm
{
mov R8, a;
mov R9, b;
movdqu XMM0, [R8];