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
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]) | |
} | |
} |
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 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 |
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 TreeNode { | |
constructor (value, left, right) { | |
this.value = value | |
this.left = left | |
this.right = right | |
} | |
invert () { | |
if (!this.left && !this.right) { | |
return this |
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 foo() { | |
console.error('foo'); | |
} | |
process.nextTick(foo); | |
console.error('bar'); | |
console.error('bar'); | |
process.nextTick(foo); | |
console.error('bar'); |
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 User { | |
private String name; | |
private int age; | |
// ... constructor | |
public String name() { | |
return 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
interface User { | |
String name(); | |
int age(); | |
} | |
class SimpleUser implements User { | |
private String name; | |
private int age; | |
//...constructor | |
String 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
'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 |
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
// 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) |
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
const keys = [ 'a', 'b', 'c' ] | |
const values = [ 1, 2, 3 ] | |
const map = {} | |
keys.forEach((k, i) => { map[k] = values[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
#!/usr/bin/env ruby | |
# | |
# JavaScript Soundfont Builder for MIDI.js | |
# Author: 0xFE <[email protected]> | |
# edited by Valentijn Nieman <[email protected]> | |
# | |
# Requires: | |
# | |
# FluidSynth | |
# Lame |
OlderNewer