Skip to content

Instantly share code, notes, and snippets.

View heimskr's full-sized avatar
🍅
hej

Kai Tamkun heimskr

🍅
hej
View GitHub Profile
@heimskr
heimskr / setperf.js
Last active February 8, 2019 11:48
setperf
const int = 10000; // set to false to test with floats (disables inclusion tests)
const n = 10000;
const m = 100;
const rand = int? () => Math.floor(Math.random() * int) : Math.random;
const T = s => console.time(t = s);
const E = s => console.timeEnd(t);
let i, j, t;
@heimskr
heimskr / loopperf.js
Created February 8, 2019 12:09
loopperf
const _ = require("lodash");
const n = 10000, m = 10000;
const T = s => console.time(t = s);
const E = s => console.timeEnd(t);
console.log("Iterations:", n);
console.log("Subiterations:", m);
console.log();
@heimskr
heimskr / keysleuth.c
Created June 14, 2019 12:30
A utility for viewing raw terminal input.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
struct termios original_attrs;
void enable_cbreak();
void restore_attrs();
void set_attrs(struct termios *attrs);
@heimskr
heimskr / twitterfix.css
Last active July 27, 2019 22:48
Partial fix for Twitter's disastrous new web interface
.css-1dbjc4n.r-150rngu.r-16y2uox.r-1wbh5a2.r-rthrr5 {
/* Also main content? */
width: 100%;
}
.css-1dbjc4n.r-1niwhzg.r-hxarbt {
/* "More v" */
display: none;
}
@heimskr
heimskr / googlefix.css
Last active February 22, 2020 04:47
Google put me in an unpleasant A/B test that changed link positions and turned them gray instead of green. This is an attempt to fix that.
.action-menu .mn-dwn-arw {
/* Down arrows next to URLs */
border-color: #006621 transparent;
}
.GHDvEf {
/* Down arrows next to URLs (parent) */
transform: translate(-2px, 29px);
}
@heimskr
heimskr / decslrm.sh
Last active September 28, 2019 23:24
Tests whether DECSLRM works properly.
#!/bin/bash
enable_hmargins() { echo -ne "\x1b[?69h"; }
disable_hmargins() { echo -ne "\x1b[?69l"; }
hmargins() { echo -ne "\x1b[$1;$2s"; } # left, right
vmargins() { echo -ne "\x1b[$1;$2r"; } # top, bottom
origin_on() { echo -ne "\x1b[?6h"; }
origin_off() { echo -ne "\x1b[?6l"; }
scroll_up() { echo -ne "\x1b[$1S"; }
scroll_down() { echo -ne "\x1b[$1T"; }
@heimskr
heimskr / slowslrm.sh
Last active September 28, 2019 23:23
If your client is so terrible that decslrm.sh crashes it, run this and count the number of times you press enter before the crash to discover the culprit.
#!/bin/bash
enable_hmargins() { echo -ne "\x1b[?69h"; }
disable_hmargins() { echo -ne "\x1b[?69l"; }
hmargins() { echo -ne "\x1b[$1;$2s"; } # left, right
vmargins() { echo -ne "\x1b[$1;$2r"; } # top, bottom
origin_on() { echo -ne "\x1b[?6h"; }
origin_off() { echo -ne "\x1b[?6l"; }
scroll_up() { echo -ne "\x1b[$1S"; }
scroll_down() { echo -ne "\x1b[$1T"; }
@heimskr
heimskr / get_core_id.cpp
Last active October 30, 2019 19:19
Returns the logical CPU core ID of the currently executing thread.
unsigned int get_core_id() {
unsigned int ebx;
__asm__("cpuid" : "=b" (ebx) : "a" (1));
// When you call cpuid with eax=1, the upper 8 bits of ebx contain the CPU ID.
return ebx >> 24;
}
unsigned int get_x2apic_id() {
unsigned int edx;
// When calling cpuid with eax=0xb, it seems you need to have ebx=0 to prevent a segfault.
@heimskr
heimskr / optional.cpp
Created February 6, 2020 04:54
Demonstrates strange behavior of std::optional
#include <iostream>
#include <optional>
#include <string>
struct Delete {
std::string str = "delete";
Delete() = delete;
Delete(const Delete &) = delete;
Delete(Delete &&) = delete;
Delete(const std::string &str_): str(str_) {
#include <iostream>
#include <map>
int main() {
int x = 0, y = 0;
enum Direction {Up, Right, Down, Left};
Direction direction = Up;
int max_extent = 1;
int extent = 0;
std::map<Direction, const char *> dirs {{Up, "up"}, {Right, "right"}, {Down, "down"}, {Left, "left"}};