- Find all references to filenames ending in
.js
:[^ ]+\.js
- Find all blank lines:
^\r?\n\r?
- Wildcard (any character and newlines):
(.|\n)+?
- Eg find all
<td>
s, regardless of content:<td>(.|\n)+?</td>
- Include attribute(s):
<td(.|\n)+?>(.|\n)+?</td>
- Include attribute(s):
- Eg find all
- Convert
getComputedStyle(foot1).left
tofoot1.getBoundingClientRect().x
: findgetComputedStyle\((.+?)\).left
and replace it with$1.getBoundingClientRect().x
- Remove all
<a>
tags, leaving just the anchor tag text: find<a[^>]*>(.*?)</a>
and replace with$1
- Only links that start with the string
/foo
:<a href="/foo[^>]*>(.*?)</a>
- Only links that start with the string
- Find all URLs:
\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]
- All URLs ending in
.jpg
:\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|](\.jpg)
- All URLs ending in
This file contains 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
// Source: ChatGPT 4 | |
function similarText(first, second) { | |
// Check for null, undefined, or empty string inputs | |
if (first === null || second === null || typeof first === 'undefined' || typeof second === 'undefined' || first.trim().length === 0 || second.trim().length === 0) { | |
return { matchingCharacters: 0, similarityPercentage: 0 }; | |
} | |
// Type coercion to ensure inputs are treated as strings | |
first += ''; | |
second += ''; |
These work best with light (~#fff
) elements (eg a code snippet or ‘card’ component) on light backgrounds.
box-shadow: 0 1px 15px rgba(27, 31, 35, .15);
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Reactive UI with Proxy object</title> | |
</head> | |
<body> | |
<!-- Comment which got me thinking: https://news.ycombinator.com/item?id=35062021 --> | |
<p>Count: | |
<span id="count"></span> | |
</p> |
This file contains 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
// Fetch JSON data | |
fetch('https://jsonplaceholder.typicode.com/todos/').then(response => { | |
// Success | |
if (response.ok) | |
return response.json(); // Returns to then() | |
// Error | |
return Promise.reject(response); |
This file contains 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
// Loop array | |
const foo = ["ane", "twa", "three"]; | |
foo.forEach(item => console.log(item)); | |
// Loop DOM elements | |
document.querySelectorAll('.foo').forEach(el => { | |
el.classList.add('bar'); // Add class, for example | |
}); |
This file contains 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
https://measurethat.net/Benchmarks/ShowResult/170533 | |
Test name | Executions per second | |
----------------------------------------------- | |
getElementById | 9,737,553 ops/sec | |
getElementsByName | 6,090,861 ops/sec | |
querySelector | 5,577,396 ops/sec | |
getElementsByTagName | 4,900,635 ops/sec | |
getElementsByClassName | 4,736,003 ops/sec |
This file contains 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
window.scrollTo({ | |
top: document.getElementById('foo').offsetTop, | |
left: 0, | |
behavior: 'smooth' | |
}); |
NewerOlder