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 |
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 | |
# 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
/* 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
// 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
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
/** | |
* 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
import React, { useEffect } from 'react'; | |
import picasso from 'picasso.js'; | |
const debounce = (func, wait, immediate = false) => { | |
let timeout; | |
return function debouncedFn(...args) { | |
return new Promise((resolve) => { | |
clearTimeout(timeout); | |
timeout = setTimeout(() => { |
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
/** | |
* Resolves the value at the given JSON path | |
* | |
* @param {String} path Path with / for children | |
* @param {Object} obj Object to use when searching | |
* @return {Object} Result at the end of the path | |
* | |
* @example | |
* let path = "/path/to/paradise"; | |
* let obj = { |
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
// ES6 Async version of the "classic" JavaScript Debounce function. | |
// Works both with and without promises, so you can replace your existing | |
// debounce helper function with this one (and it will behave the same). | |
// The only difference is that this one returns a promise, so you can use | |
// it with async/await. | |
// | |
// I've converted this into a TypeScript module, and added a few more | |
// features to it, such as the ability to cancel the debounce, and also | |
// execute the function immediately, using the `doImmediately` method. | |
// |
NewerOlder