Skip to content

Instantly share code, notes, and snippets.

View Aleksey-Danchin's full-sized avatar

Алексей Данчин Aleksey-Danchin

View GitHub Profile
@Aleksey-Danchin
Aleksey-Danchin / det.js
Created April 10, 2015 09:55
Determinant of quadratic matrix
function det (argStr) {
var numbers = argStr.split(' ').map(Number),
length = Math.sqrt(numbers.length);
if ((length % 1) !== 0) return false;
if (length === 1) return numbers[0];
if (length === 2) return numbers[0] * numbers[3] - numbers[1] * numbers[2];
var matrica = [];
for (var i = 0; i < length; i++) {
@Aleksey-Danchin
Aleksey-Danchin / isIntersection.js
Last active August 29, 2015 14:19
Функция определения факта пересечения двух отрезков на 2-х мерной декартовой системе координат.
function isIntersection (x1, y1, x2, y2, x3, y3, x4, y4) {
var point1 = {x: x1, y: y1},
point2 = {x: x2, y: y2},
point3 = {x: x3, y: y3},
point4 = {x: x4, y: y4};
var line1 = {},
line2 = {};
init();
@Aleksey-Danchin
Aleksey-Danchin / getSimpleArray.js
Last active August 29, 2015 14:20
Функция возвращает массив всех простых чисел меньших или равных единственному аргументу.
function getSimpleArray (N) {
var preparation = new Int8Array(N + 1), retArray = [], i, j;
if (N >= 2) retArray.push(2);
for (i = 3; i <= N; i += 2) {
if (preparation[i] !== 0) continue;
retArray.push(i);
j = i * 2;
while (j <= N) {
preparation[j] = 1;
j += i;
function setIntervalControlling (callback, time) {
var startMoment = (new Date).getTime(),
number = 0, timeOfLoop = 0, difference = 0,
realTime = time, minStep = Math.pow(2, -4);
var loop;
__restart();
return { stop: function () { clearInterval(loop); } };
@Aleksey-Danchin
Aleksey-Danchin / insertSort.js
Created July 15, 2015 09:04
Sort by Insert Method.
function insertSort (array) {
for (var i = 1; i < array.length; i++) {
var key = array[i], j = i - 1;
while (j > -1 && array[j] > key)
array[j + 1] = array[j--];
array[j + 1] = key;
}
@Aleksey-Danchin
Aleksey-Danchin / binSum.js
Created July 15, 2015 09:38
Bitwise suma.
function sum (a, b) {
var c = [], buff = false;
for (var i = a.length - 1; i >= 0; i--)
if ((a[i] && b[i]) || (!a[i] && !b[i])) {
c.unshift(buff);
buff = a[i];
} else c.unshift(!buff);
if (buff) c.unshift(true);
@Aleksey-Danchin
Aleksey-Danchin / FirstTimeUbuntu
Last active August 29, 2015 14:25
First time Ubuntu softwares install command.
sudo apt-get install thunderbird apache2 mysql-server php5-mysql php5 libapache2-mod-php5 php5-mcrypt git gitk npm vim htop ssh traceroute vlc
@Aleksey-Danchin
Aleksey-Danchin / formated.js
Last active October 17, 2015 06:31
Форматирование страницы в firefox.
// Удаление шапки в которой написн вариант.
$('div.header').remove();
// Удаление номеров каждого задания.
var elements = $('.nobreak.pbody').find('span');
for (var i = 0; i < elements.length; i++) {
var element = $(elements[i]),
text = element.text(),
index = text.indexOf('.'),
text = '№ ' + text.substr(0, index) + ')';
@Aleksey-Danchin
Aleksey-Danchin / isIntersection.js
Created January 21, 2016 22:49
isIntersection (v2 teory)
function isIntersection (x1, y1, x2, y2, x3, y3, x4, y4) {
var angles = [
getAngleOf(x2, y2, x1, y1, x3, y3) + getAngleOf(x2, y2, x1, y1, x4, y4),
getAngleOf(x4, y4, x3, y3, x1, y1) + getAngleOf(x4, y4, x3, y3, x2, y2),
getAngleOf(x1, y1, x2, y2, x3, y3) + getAngleOf(x1, y1, x2, y2, x4, y4),
getAngleOf(x3, y3, x4, y4, x2, y2) + getAngleOf(x3, y3, x4, y4, x1, y1)
];
var sum = angles[0] + angles[1] + angles[2] + angles[3];
@Aleksey-Danchin
Aleksey-Danchin / cat.js
Created June 27, 2016 11:54
Скрипт поика разреза на одинаковые части.
"use strict";
let res = `
1111110
1111100
1111111
1111111
1111111
0111111
0111111