Skip to content

Instantly share code, notes, and snippets.

View kyr0's full-sized avatar
✴️
hyperfocus

Aron Homberg kyr0

✴️
hyperfocus
View GitHub Profile
@kyr0
kyr0 / wp-node-timsort.js
Last active March 24, 2019 09:29
wp-node-timsort
'use strict';
const DEFAULT_MIN_MERGE = 32;
const DEFAULT_MIN_GALLOPING = 7;
const DEFAULT_TMP_STORAGE_LENGTH = 256;
const POWERS_OF_TEN = [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9]
const log10 = (x) => {
if (x < 1e5) {
if (x < 1e2) {
return x < 1e1 ? 0 : 1;
}
@kyr0
kyr0 / wp-node-quicksort.js
Created March 24, 2019 09:00
wp-node-quicksort
'use strict';
const quickSort = (arr, dimension, left = 0, right = arr.length - 1) => {
const len = arr.length; let index;
if (len > 1) {
index = partition(arr, dimension, left, right);
if(left < index - 1) quickSort(arr, dimension, left, index - 1);
if(index < right) quickSort(arr, dimension, index, right);
}
return arr;
};
@kyr0
kyr0 / wp-node.js
Created March 24, 2019 08:18
wp-node.js
'use strict';
const fs = require('fs');
const startTime = Date.now();
const log = (msg) => setImmediate(() => { process.stdout.write(msg); });
fs.readFile("/dev/stdin", 'utf8', (err, text) => {
const map = {}, sorted = [], lines = text.split("\n");
for (let i=0; i<lines.length; i++) {
const words = lines[i].split(' ');
for (let j=0; j<words.length; j++) {
if (words[j].length === 0) continue;
@kyr0
kyr0 / tab-hidden.directive.ts
Created June 26, 2017 18:44
Ionic 3 TabHiddenDirective to programmatically hide tabs using [tab-hidden]="true"; it is adaptive and also works fine on view changes
import {Directive, ElementRef, Input} from '@angular/core';
@Directive({ selector: '[tab-hidden]' })
export class TabHiddenDirective {
@Input('tab-hidden')
tabHidden: boolean;
private _tabElCache: Map<string, Element> = new Map();