This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* permute(permutation) { | |
let length = permutation.length; | |
let c = Array(length).fill(0); | |
let i = 1; | |
let k; | |
let p; | |
yield permutation; | |
while (i < length) { | |
if (c[i] < i) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Enum { | |
constructor(name, value) { | |
if (this.constructor._nameValue.has(name)) { | |
throw new Error(`Duplicate name: ${name}`); | |
} | |
if (this.constructor._valueName.has(value)) { | |
throw new Error(`Duplicate value: ${value}`); | |
} | |
Object.defineProperties(this, { | |
name: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatRepeatingDecimal(num) { | |
num = num.toString(); | |
var p = num.split('.'); | |
if (p.length === 1) { | |
return p[0]; | |
} | |
// match parts (prefix, repeating, suffix): | |
var m = /^(\d*?)(\d{1,})\2{2,}(\d*?)$/.exec(p[1]); | |
if (!m) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bytes = [ | |
0xff0000, 0x00ff00, 0x0000ff, | |
0x0000cc, 0xcc0000, 0x00cc00, | |
0x00ee00, 0x0000ee, 0xee0000, | |
]; | |
var img = pixelsToImage(bytes); | |
console.log(img.src); | |
img.width = 90; | |
img.height = 90; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"strings" | |
) | |
type SortedStrArray []string | |
func NewSortedStrArray(arr []string) (*SortedStrArray) { | |
res := SortedStrArray(arr) | |
return &res | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.expectResult = async function expectResult(interval, timeout, expectValue) { | |
if (interval <= 0) | |
interval = 1000; | |
var fn = this; | |
var timeStart = Date.now(); | |
var tries = 0; | |
function check() { | |
var value, error, asExpected; | |
try { | |
value = fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function p2d(a, r) { | |
return [ | |
r * Math.cos(a), | |
r * Math.sin(a), | |
]; | |
} | |
function p_distance(a0, r0, a1, r1) { | |
var d0 = p2d(a0, r0); | |
var d1 = p2d(a1, r1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // I don't know why anybody may need it | |
class Promise { | |
protected $resolvers = []; | |
protected $catchers = []; | |
protected $value = null; | |
protected $error = null; | |
protected $status = 'idle'; | |
public function __construct($run, $manualStart = false) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var generateSvgAvatar = (function () { | |
return function (seed, raw) { | |
var rands = hash320('' + seed); | |
var randsHex = rands.map(function (v) { | |
return ('00' + v.toString(16)).slice(-2); | |
}).join(''); | |
rands = rands.concat(rands); | |
var globalRotation = 360 * rands[rands[0] % 20] / 0xff; | |
var particles = []; | |
var n = 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.enableChaining = function (obj) { | |
if (!obj || typeof obj !== 'object') | |
throw new TypeError("Argument obj is not an Object"); | |
var names = {}; | |
var protos = []; | |
var cur = obj; | |
var descr; | |
while (cur && protos.indexOf(cur) < 0) { | |
descr = Object.getOwnPropertyDescriptors(cur); | |
for (var k in descr) { |
NewerOlder