Skip to content

Instantly share code, notes, and snippets.

@osiyuk
osiyuk / BTree.cpp
Created October 21, 2018 01:27 — forked from pervognsen/BTree.cpp
B-tree with iterators and more aggressive deletion
enum { BMAX = 32, BMIN = BMAX / 2, BHEIGHT = 6 };
struct BNode {
uint32_t length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
};
};
@osiyuk
osiyuk / object.assign.js
Last active November 13, 2016 20:45 — forked from spiralx/object-assign.js
Object.assign() polyfill
if (!Object.assign) {
Object.defineProperty(Object, 'assign', {
enumerable: false,
configurable: true,
writable: true,
value: function (target) {
'use strict';
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}
@osiyuk
osiyuk / string.prototype.format.js
Last active November 24, 2016 23:49 — forked from jonathanconway/string.prototype.format.js
Straight-forward string.prototype format method for Javascript.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
// it`s monkey patching, breaks incapsulation and considered bad practice
String.prototype.format = function() {
var s = this;
for (var i = 0; i < arguments.length; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i]);
}
return s;