NostraDavid's Knowledge Base
Javascript code snippets and regex, and the likes
Note to self: GitHub Gist existsβ¦
Regular Expressions
Use in combination with $0/$1/$2... to find and replace text.
| note | regex |
|---|---|
|
Find the nth comma, via stackoverflow; Edit the number in between {} to find the nth comma. |
,(?=(?:[^,]*,){3}[^,]*$) |
| Every line that doesn't start with a . via regex; I was trying to filter bootstrap.css from all non-classes |
^((?!^\.).)*$ |
| Filter everything from a : till the end of the line | [:].*$ |
| Find non-ASCII letters in vscode; Great for finding unicode characters in copied code, because Haskell can't handle Unicode in your comments... |
([^\x00-\x7F]) |
| hit him up when you pay for WoW | Craizler-TarrenMill |
| WoW BattleTag | Cyrstad#2776 |
| Find main content of HTML page | <main>\n\t+<section>((\n.*?)*)</section>(\n\t+)</main> |
| find paragraph tags that aren't closed | \t+<p>.*(?<!</p>)$ |
find all lines that do not contain hede |
^((?!hede).)*$ |
Online Tools
These are websites/webpages that I use to optimize this site.
| Tool name | What to use it for |
|---|---|
| SVGOMG! | "SVG Optimizer's Missing GUI", an online SVG optimizer |
| Boxy SVG editor | Usually I edit my SVG files by hand, but sometimes I need some basic shapes placed. |
| Squoosh | Google Chrome Labs created this site so you can customize the compression of your image (and compare it with the original). Desktop version is also available. |
| Diagrams.net (previously Draw.io) | Used for diagrams. If you save a file as PNG you can open it as PNG with an image viewer and and with the website or Desktop version |
Javascript oneliners
Small scripts that I run in the browser to manipulate a website (like remove my reddit comments from a specific subreddit, for example)
| note | code |
|---|---|
| Open all collapsed comments on a reddit comment page |
|
Manipulating Unicode strings per code point, not per byte. "".split() gives you bytes, not codepoints |
Array.from("π±π’π°π±π¦π«π€ ππππ #@$%#^$% π±π’π°π±π¦π«π€ ππππ"); |
Remove all .bighead classed elements (no Array.from() needed, which is what I used before, so I could use map() instead of a for loop) |
|
| Make console.log use colors |
|
| This opens all are you sure? dialogs for comments, on a profile page of Reddit |
|
| Removing duplicates |
|
| Run a timed loop (handy for interacting with Reddit, because Reddit has a rate limit of 30 requests per minute) |
|
| Remove all comments from a specific subreddit (TheLastOfUs2, in this case) |
|
| Use on Twitch to track the amount of currently used emotes |
|