Skip to content

Instantly share code, notes, and snippets.

🎵
in unison

Guseyn Ismayylov Guseyn

🎵
in unison
View GitHub Profile
@Guseyn
Guseyn / solution.js
Created Mar 25, 2019
theorem.applytojob.com solution
View solution.js
const assert = require('assert')
function flattenArray (nestedArray, resArray = []) {
for (let i = 0; i < nestedArray.length; i++) {
if (Array.isArray(nestedArray[i])) {
flattenArray(nestedArray[i], resArray)
} else {
resArray.push(nestedArray[i])
}
}
@Guseyn
Guseyn / mapLimit.js
Last active Apr 16, 2019
mapLimit via callbacks
View mapLimit.js
function mapLimit (col, limit, mapFunc, doneFunc, newCol = [], index = { value: 0 }, freeThreads = { value: limit }) {
if (freeThreads.value > 0 && index.value < col.length) {
// Save current index
const curIndex = index.value
// Now the number of free threads is lower on 1
freeThreads.value -= 1
mapFunc((err, newItem) => {
if (err) {
// Smth bad happend, we call doneFunc with err
@Guseyn
Guseyn / invertTree.js
Last active Apr 9, 2019
Invert Tree In Pure OO style
View invertTree.js
class TreeNode {
constructor (value, left, right) {
this.value = value
this.left = left
this.right = right
}
invert () {
if (!this.left && !this.right) {
return this
View next-tick.js
function foo() {
console.error('foo');
}
process.nextTick(foo);
console.error('bar');
console.error('bar');
process.nextTick(foo);
console.error('bar');
@Guseyn
Guseyn / d.java
Last active Mar 23, 2020
Declarative approach via getters
View d.java
class User {
private String name;
private int age;
// ... constructor
public String name() {
return this.name;
}
@Guseyn
Guseyn / declarative-interface.java
Created Mar 23, 2020
Declarative approach via interface with getters
View declarative-interface.java
interface User {
String name();
int age();
}
class SimpleUser implements User {
private String name;
private int age;
//...constructor
String name () {
@Guseyn
Guseyn / boundsOfCurve.js
Created Apr 29, 2020
Bezier Bounding Box
View boundsOfCurve.js
'use strict'
// based on the same code in python https://gist.github.com/internetimagery/642b9cfa8488ba9a4d7c
const boundsOfCurve = (x0, y0, x1, y1, x2, y2, x3, y3) => {
const tvalues = []
const bounds = [[], []]
const points = []
for (let i = 0; i <= 1; i++) {
let b
@Guseyn
Guseyn / bezier-svg-path-interpolation.js
Created Jun 20, 2020
Bezier curve interpolation as svg path
View bezier-svg-path-interpolation.js
// Based on this excellent article (https://apoorvaj.io/cubic-bezier-through-four-points/)
const vectorLength = (p1, p2) => {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2))
}
const middleCurvePoints = (firstPoint, secondPoint, thirdPoint, fourthPoint, alpha, epsilon) => {
const d1 = Math.pow(vectorLength(secondPoint, firstPoint), alpha)
const d2 = Math.pow(vectorLength(thirdPoint, secondPoint), alpha)
const d3 = Math.pow(vectorLength(fourthPoint, thirdPoint), alpha)
You can’t perform that action at this time.