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
| var os = require('os'); | |
| var home = os.homedir(); | |
| var cwd = process.cwd(); | |
| if (cwd.substring(0, home.length) === home) { | |
| cwd = cwd.replace(home, '~') | |
| } | |
| var items = cwd.split('/'); | |
| var isAbsolute; |
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
| # So here's my directory structure | |
| # . | |
| # ├── a | |
| # │ └── test.sh | |
| # ├── b | |
| # │ └── test.sh | |
| # └── test.sh | |
| find . -name *.sh |
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
| // general | |
| fps_max 0 | |
| closeonbuy 1 | |
| gameinstructor_enable 0 | |
| bind p "exec autoexec" | |
| // net graph | |
| net_graph 1 | |
| net_graphpos 2 |
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 promisify(fn) { | |
| return (...args) => { | |
| return new Promise((resolve, reject) => { | |
| fn(...args, (error, ...result) => { | |
| error ? reject(error) : resolve(...result); | |
| }) | |
| }) | |
| } | |
| } |
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 cors(req, res, next) { | |
| console.log('in cors middleware:'); | |
| req.cors = 'enabled'; | |
| console.log(req); | |
| next(); | |
| } | |
| function logger(req, res, next) { | |
| console.log('in logger middleware:'); | |
| req.logged = true; |
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 readline = require('readline') | |
| function drawProgress(current, total, promptLength = 25) { | |
| const percentComplete = current / total | |
| const visualPercent = Math.round(percentComplete * 100) | |
| const inProgressLength = Math.round(promptLength * percentComplete) | |
| const filledBar = rightPad('='.repeat(inProgressLength), ' ', promptLength) | |
| readline.cursorTo(process.stdout, 0) | |
| process.stdout.write(`[${filledBar}] ${visualPercent}%`) | |
| } |
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
| /** | |
| * Retries a function that returns a promise a given number of times and backs | |
| * off each attempt exponentially. | |
| * | |
| * @param {Function} promiseGenerator The function to retry. | |
| * @param {number} [attempts=5] Number of attempts to make. | |
| * @param {number} [delay=1000] Initial delay between attempts in ms. | |
| * @return {Promise} | |
| */ | |
| function attemptWithRetry(promiseGenerator, attempts = 5, delay = 100) { |
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 clearConsole() { | |
| return process.stdout.write('\033c'); | |
| } | |
| // run this at before app.listen() to clear console, great with tools like nodemon | |
| // Edit: or you could use the builtin console.clear() lol |
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
| /** | |
| * largestRemainderRound will round each number in an array to the nearest | |
| * integer but make sure that the the sum of all the numbers still equals | |
| * desiredTotal. Uses largest remainder method. Returns numbers in order they | |
| * came. | |
| * | |
| * @param {number[]} numbers - numbers to round | |
| * @param {number} desiredTotal - total that sum of the return list must equal | |
| * @return {number[]} the list of rounded numbers | |
| * @example |
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
| touch output.csv # file with the end result | |
| for i in {1..10}; do # replace with your "for every file loop" | |
| sh ./program.sh | tr ' ' '\n' > tempfile1 # program.sh is your software, we pipe it into tr to split it into a column | |
| paste -d ',' tempfile1 output.csv > tempfile2 # paste the column with a delimeter to a tempfile | |
| mv tempfile2 output.csv # clean up the tempfiles on every iteration | |
| rm tempfile1 | |
| done |