Skip to content

Instantly share code, notes, and snippets.

View JTRNS's full-sized avatar
💤

JT JTRNS

💤
  • The Netherlands
  • 21:42 (UTC +02:00)
View GitHub Profile
@JTRNS
JTRNS / chmod_ssh.sh
Created March 13, 2021 18:59
ssh permissions fix
#!/usr/bin/env bash
echo "fixing permissions for ssh"
# rwx --- ---
chmod 700 $HOME/.ssh
# if it is not a public key, -rw --- --- (inc. conf, auth_hosts)
find $HOME/.ssh -type f ! -name "*.pub" -print0 | xargs -0 chmod 600
# -rw r-- r--
@JTRNS
JTRNS / oxford5000.js
Created March 9, 2021 20:31
Oxford 5000 Wordlist
// handy wordlist from https://www.oxfordlearnersdictionaries.com/wordlists/oxford3000-5000
// copy is a copy to clipboard helper in browser devtools
copy(Array.from(document.querySelectorAll('#wordlistsContentPanel .top-g li')).map(li => {
const { hw, ox5000 } = li.dataset;
return { word: hw, level: ox5000, type: li.querySelector('span').innerText };
}));
@JTRNS
JTRNS / typewriter.sh
Created March 9, 2021 20:23
write first, edit later
#!/bin/bash
# write first, edit later
# toggles the function of the backspace key between
# its normal function and that of the delete key
# Keycode might be different for other keyboards!
# to find the right keycode on your hardware use:
# xev -event keyboard
@JTRNS
JTRNS / nodebin.js
Last active July 30, 2020 20:36
Codebin | Saving code snippets that would otherwise have ended up in the bin
const fs = require('fs');
const path = require('path');
async function recurseDir (dirPath) {
const dir = await fs.promises.opendir(dirPath);
const allPaths = [];
for await (const dirent of dir) {
if (dirent.isDirectory()) {
const childPaths = await recurseDir(path.join(dirPath, dirent.name))
childPaths.map(p => allPaths.push(p))
@JTRNS
JTRNS / find-pagination.js
Last active June 10, 2020 13:45
Locate the pagination element on a webpage
/*
Function to find the pagination element on a webpage
with reasonable accuracy.
*/
function findPagination() {
const pagElem =
Array.from(document.querySelectorAll('body *'))
.filter(el => el.nodeType === 1 && el.nodeName !== 'SCRIPT')
.filter(el => el.innerHTML.match(/>[\t\n\r\s]*\d[\t\n\r\s]*</g) !== null )
@JTRNS
JTRNS / data-scraper.js
Last active May 17, 2020 11:20
Functional scraping: A reusable function for extracting data from websites.
function extractDataFrom(element) {
return (options) => {
let data = {}
options.forEach(option => {
const targetElem = element.querySelector(option.selector);
let targetValue;
switch (option.attribute) {
case 'text':
targetValue = targetElem ? targetElem.innerText.trim() : '';
break;