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
| /** | |
| * Same as Promise.all(items.map(item => task(item))), but it waits for | |
| * the first {batchSize} promises to finish before starting the next batch. | |
| * | |
| * Usage: | |
| * const results = await batchPromise(STUFF_TO_DO, 5, async (ITEM_TO_DO) => { | |
| * console.log('Fetching', ITEM_TO_DO.url); | |
| * return await fetch(ITEM_TO_DO.url); | |
| * }); | |
| * |
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 groupBy = (array, fn, last = false) => { | |
| const grouped = []; | |
| for (let index = 0; index < array.length; index += 1) { | |
| const element = array[index]; | |
| const key = fn(element); | |
| const foundIndex = grouped.findIndex((v) => v.key === key); | |
| if (foundIndex === -1) { | |
| grouped.push({ key, value: element }); | |
| } else if (last) { |
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
| // Paste the code below into your webbrowser console and press "enter" | |
| // To open the console you can press "F12" or "Ctrl + Shift + J" for most browsers. | |
| // Read more here: https://appuals.com/open-browser-console/ | |
| // Instructions video on my twitter: https://twitter.com/_carlhannes/status/1590441813445599232 | |
| // The code re-tries fetching data if it gets status 429, which is the error that the SJ page has | |
| // It does this together with an exponential back-off delay which is common to use with microservices of this type | |
| // Because of these re-tries and the delay, the overall load of the website and the servers will be lower, | |
| // since it does not need to re-fetch requests that actually succeed. Read more on my twitter if you're interested: | |
| // https://twitter.com/_carlhannes/status/1590605735314206721 |
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
| /* eslint-disable no-await-in-loop */ | |
| import * as fs from 'fs/promises'; | |
| import * as path from 'path'; | |
| const checkIfExist = async (p: string) => fs.access(p).then(() => true).catch(() => false); | |
| function msg(...args: any[]) { | |
| console.info('🐋:', ...args); | |
| } |
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
| #!/bin/bash | |
| # Check if the user is root | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "This script must be run as root" | |
| exit 1 | |
| fi | |
| # Create user and usergroup | |
| groupadd -f boringproxy |
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
| #!/bin/bash | |
| # | |
| # wget -q -O - https://gist.github.com/carlhannes/0a8c827f826d330cfc07b36365e5158e/raw/a4d4ad961d4ba9637d7c7f92c1537e6437a289d9/setup-eslint-airbnb.sh | bash | |
| # | |
| # Step 0: Determine ESLint package and configuration based on project dependencies | |
| PACKAGE_JSON="package.json" | |
| ESLINT_PACKAGE="eslint-config-airbnb-base" |
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
| #!/bin/bash | |
| # 1. Check and install hdparm if not installed | |
| if ! which hdparm > /dev/null; then | |
| echo "hdparm not found! Installing..." | |
| apt-get update | |
| apt-get install -y hdparm | |
| fi | |
| # 2. List HDDs |
OlderNewer