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 | |
abstract class Struct | |
{ | |
protected static array $defaultProps = []; | |
protected static string $packFmt = ''; | |
protected static string $unpackFmt = ''; | |
protected array $props = []; |
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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { width: 100%; height: 100%; } | |
path { | |
fill: none; | |
stroke: teal; |
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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { width: 100%; height: 100%; } | |
path { | |
fill: none; | |
stroke: teal; |
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 secretSanta(values, mutuality = 0.5) { | |
let offset = 0; | |
return values | |
.map((val, index) => ({index: index, order: Math.random()})) | |
.sort((a, b) => a.order - b.order) | |
.map((item, next, items) => { | |
[next, offset] = (++next - offset > 1 && items.length - next > 1 && Math.random() < mutuality) | |
? [offset, next] | |
: [next < items.length ? next : offset, offset]; | |
return [values[item.index], values[items[next].index]]; |
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 secretSanta(values, mutualEnabled = true) { | |
var indexes = []; | |
indexes.length = values.length; | |
indexes = indexes.fill(0) | |
.map((v, i) => { return {index: i, order: Math.random()} }) | |
.sort((a, b) => a.order - b.order) | |
.map(item => item.index) | |
; | |
var fraglen = left => { | |
let count = Math.max(2, Math.ceil(left * Math.random())); |
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 | |
function permute($items) { | |
$permutes = []; | |
permute_pairs($items, [], $permutes); | |
return $permutes; | |
} | |
function permute_pairs($items, $parents = [], &$out = []) { | |
for ($i = 0, $l = count($items); $i < $l; $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
dec: 117 x 73 | |
hex: 0x75 x 0x49 | |
пусть в нашем примере максимальный int = 0xFF | |
тогда разобьем число по разрядам в половину маскимального (чтобы умещались переполнения в старшие разряды) | |
vecs: [0x07, 0x05] x [0x04, 0x09] | |
mul: | |
расширяем в 2 раза результирующий вектор |
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
# Drop all local branches except current and master | |
git branch | grep -v "master" | grep -v ^* | xargs git branch -D |
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 calcHexColumn(r, i) { | |
var s = r + Math.abs(1.5 * r * r + 1.5 * r - i - 1); | |
var a = Math.ceil(2 * r + 1.5 - Math.sqrt((2 * r + 1.5) * (2 * r + 1.5) - 2 * s)) - 1; | |
var m = 2 * Math.floor(2 * i / (3 * r * r + 3 * r + 1)) - 1; | |
return m * a + r; | |
} | |
calcHexColumn(3, 22); // 4 |
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 loopNum(x, lim) { | |
return x - lim * Math.floor(x / lim); | |
} | |
console.log([ | |
loopNum(1, 360), // 1 | |
loopNum(361, 360), // 1 | |
loopNum(-1, 360), // 359 | |
loopNum(-361, 360), // 359 | |
loopNum(0.1, 3.1415), // 0.1 |
NewerOlder