This file contains hidden or 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
| [ | |
| { "id": 1, "name": "Berlin Hbf", "city": "Berlin", "lat": 52.5251, "lng": 13.3694 }, | |
| { "id": 2, "name": "Berlin Ostbahnhof", "city": "Berlin", "lat": 52.5108, "lng": 13.4348 }, | |
| { "id": 3, "name": "Berlin Südkreuz", "city": "Berlin", "lat": 52.475, "lng": 13.365 }, | |
| { "id": 4, "name": "Hamburg Hbf", "city": "Hamburg", "lat": 53.553, "lng": 10.0067 }, | |
| { "id": 5, "name": "Hamburg Altona", "city": "Hamburg", "lat": 53.5526, "lng": 9.935 }, | |
| { "id": 6, "name": "Hamburg Dammtor", "city": "Hamburg", "lat": 53.5603, "lng": 9.9886 }, | |
| { "id": 7, "name": "Munich Hbf", "city": "Munich", "lat": 48.1402, "lng": 11.5586 }, | |
| { "id": 8, "name": "Munich Ost", "city": "Munich", "lat": 48.1277, "lng": 11.6034 }, | |
| { "id": 9, "name": "Munich Pasing", "city": "Munich", "lat": 48.1499, "lng": 11.4616 }, |
This file contains hidden or 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 calculateAngle(point1, point2) { | |
| const angleInRadians = Math.atan2(point2.y - point1.y, point2.x - point1.x); | |
| const angleInDegrees = (angleInRadians * 180) / Math.PI; | |
| return angleInDegrees; | |
| } |
This file contains hidden or 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 getStd(array) { | |
| const n = array.length; | |
| const mean = array.reduce((a, b) => a + b) / n; | |
| return Math.sqrt( | |
| array.map(x => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n | |
| ); | |
| } |
This file contains hidden or 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 findLineEquation(point1, point2) { | |
| const slope = (point2.y - point1.y) / (point2.x - point1.x); | |
| const yIntercept = point1.y - slope * point1.x; | |
| return { slope, yIntercept }; | |
| } | |
| function findCorrespondingY(point1, point2, x) { | |
| const lineEquation = findLineEquation(point1, point2); | |
| return lineEquation.slope * x + lineEquation.yIntercept; | |
| } |
This file contains hidden or 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
| // https://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript | |
| function randomIntFromInterval(min, max) { // min and max included | |
| return Math.floor(Math.random() * (max - min + 1) + min) | |
| } | |
| const rndInt = randomIntFromInterval(1, 6) | |
| console.log(rndInt) |
This file contains hidden or 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 { useState } from "react"; | |
| const { REACT_APP_API_URL, REACT_APP_API_VERSION } = process.env; | |
| const buildUrl = (pathname, query) => { | |
| const apiUrl = `${REACT_APP_API_URL}api/v${REACT_APP_API_VERSION}`; | |
| const url = new URL(apiUrl + pathname); | |
| Object.keys(query).forEach(queryKey => | |
| url.searchParams.set(queryKey, query[queryKey].toString()) | |
| ); |
This file contains hidden or 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 getFields(array, fields = []) { | |
| return array.map(item => | |
| fields.length === 1 | |
| ? item[fields[0]] | |
| : new Array(fields.length).fill(null).map((_, i) => item[fields[i]]) | |
| ) | |
| } | |
| // How to use? | |
| const arr = [{ id: 1, name: "Steve" }, { id: 2, name: "Bill" }] |
This file contains hidden or 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 sleep = ms => { | |
| return new Promise(resolve => { | |
| setTimeout(resolve, ms); | |
| }) | |
| } | |
| // How to use? | |
| await sleep(5000) |
This file contains hidden or 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 _ from "lodash" | |
| import { formatBytes } from "./format" // https://gist.github.com/neysidev/71d6100023c4359a5cff256f2601c333 | |
| const openBrowseWindow = ({ | |
| accept = [], | |
| multiple = false, | |
| onChange = () => {}, | |
| }) => { | |
| // Initialize the file input | |
| const input = document.createElement("input") |
This file contains hidden or 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 fs = require("fs") | |
| fs.readFile("input.csv", "utf8", (err, data) => { | |
| if (err) return console.log(err) | |
| const content = [] | |
| data.split("\n").forEach(line => { | |
| content.push(line.split(",")) | |
| }) |
NewerOlder