Skip to content

Instantly share code, notes, and snippets.

View JTRNS's full-sized avatar
💤

JT JTRNS

💤
  • The Netherlands
  • 11:34 (UTC +02:00)
View GitHub Profile
@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;
@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 / 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 / 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 / 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 / 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 / adjectives.txt
Last active March 18, 2021 18:27
A wordlist consisting of 5069 English adjectives.
# list has not been checked manually for duplicates and spelling mistakes.
a
aback
abaft
abandoned
abashed
abdominal
aberrant
abhorrent
abiding
@JTRNS
JTRNS / clean_win10_startmenu.ps1
Created June 14, 2021 06:49
Copy all links from start menu subdirectories into start menu programs directory
# Windows uses some of the .lnk files in the start menu to launch system utilities. So copy,
# but do not move / remove links like Powershell.
# system and user start menu directories
$SystemStartMenuDir = "$env:ProgramData\Microsoft\Windows\Start Menu\Programs"
$UserStartMenuDir = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs"
# copy links (.lnk files) from system start menu directory to user start menu directory
Get-ChildItem -Path $SystemStartMenuDir -File -Include "*.lnk" -Recurse | Copy-Item -Destination $UserStartMenuDir
@JTRNS
JTRNS / blingbling.js
Created September 25, 2021 11:15
A more shiny variation of the popular bling dot js
/* blingbling.js */
window.$ = document.querySelector.bind(document);
window.$$ = document.querySelectorAll.bind(document);
HTMLElement.prototype.$ = function (selector) {
return this.querySelector(selector);
}
HTMLElement.prototype.$$ = function (selector) {
@JTRNS
JTRNS / SmartJoin.py
Created April 7, 2022 08:52
Create vertex groups for each mesh before joining objects in Blender
bl_info = {
"name": "Smart Join",
"author": "Jeroen Trines",
"version": (1, 0),
"blender": (3, 1, 0),
"location": "View3D > Object > Smart Join",
"description": "Create vertex groups for each mesh before joining objects in Blender",
"warning": "",
"doc_url": "",
"category": "Object",