Skip to content

Instantly share code, notes, and snippets.

View Vladislao's full-sized avatar

Vladislav Stroev Vladislao

View GitHub Profile
@Vladislao
Vladislao / bisect.js
Created October 12, 2023 10:37
Binary search
const bisect = (l, r, cond) => {
while (l <= r) {
const m = (l + r) >> 1;
if (cond(m)) {
l = m - 1;
} else {
r = m + 1;
}
}
return l;
@Vladislao
Vladislao / UnionFind.js
Last active October 12, 2023 10:40
UnionFind or Disjoint-set
class UnionFind {
constructor(size) {
this.groups = new Array(size);
this.ranks = [];
for(let i = 0; i < size; i++) {
this.groups[i] = i;
}
}
find(node) {
@Vladislao
Vladislao / index.sh
Created April 4, 2018 11:21
Delete ifstate files which didn't correspond to any of the interfaces listed by ifconfig
find /run/network -name 'ifstate.*' | egrep -w -v -e `ifconfig | grep veth | cut -d' ' -f1 | xargs echo | tr ' ' '|'` | xargs -n1 rm