Skip to content

Instantly share code, notes, and snippets.

View netsi1964's full-sized avatar

Sten Hougaard netsi1964

View GitHub Profile
@netsi1964
netsi1964 / samples.json
Last active July 28, 2023 13:28
Test your CSS selector skills
[
{
"pattern": "h1~div:first-of-type .button[data-type=\"submit\"]:not(.disabled)",
"description": "Selects an element with class 'button' and data attribute 'data-type' set to 'submit', that is also not 'disabled', which is a descendant of the first element of type 'div' that comes after an 'h1' element.",
"elementName": "",
"classes": [
"button"
],
"example": "\t<h1>Title</h1>\r\n\t<div>\r\n\t\t<button class=\"button\" data-type=\"submit\">Submit</button>\r\n\t</div>\r\n\t<div>\r\n\t\t<button class=\"button\" data-type=\"cancel\">Cancel</button>\r\n\t</div>\r\n\t<div>\r\n\t\t<button class=\"button\" data-type=\"submit\" disabled>Disabled</button>\r\n\t</div>",
"note": ""
@netsi1964
netsi1964 / generate_prompt_quiz.js
Last active June 25, 2023 13:59
Generate ChatGPT fun quiz from dr.dk
if (document.location.href.includes("dr.dk")) {
// Reading (bad) news can be hard.
// This script you should run in the console and then hover over headlines to get a new random headline.
// Simply copy it
// Open developer toolbar (press F12)
// In the "console" paste the script, press ENTER
// Enjoy! Simply hover over a headline to get a new random text :-)
// Try reading it seeing the photo together with the new random text
// THIS VERSION is for https://www.dr.dk
//
@netsi1964
netsi1964 / Geometry.js
Last active May 20, 2023 08:08
A useful class when working with Geometry
/**
* A class for basic geometric calculations.
*/
export default class Geometry {
static PI = 3.141592653589793;
static circleArea(radius) {
if (radius < 0) {
throw new Error("Radius cannot be negative");
@netsi1964
netsi1964 / variousJS.js
Created March 13, 2013 20:50
Javascript: various javascript
function camelCase(selector) {
var cc = '';
[].forEach.call(document.querySelector(selector).value.split(' '), function(e) {
cc+=e.substr(0,1).toUpperCase()+e.substr(1,200).toLowerCase();
});
return cc;
}
@netsi1964
netsi1964 / scrollmania.js
Created September 19, 2022 12:15
Pretend that scrolling around a page happens :-)
let all = Array.from(document.querySelectorAll('*'));
setInterval(() => {
all[Math.floor(Math.random()*all.length)].scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"})
}, 800)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@netsi1964
netsi1964 / svg-utils.js
Last active April 18, 2022 07:09
Some SVG utils
export screen2svg = (eleSvg, x, y) => {
const point = eleSvg.createSVGPoint();
point.x = x;
point.y = y;
return point.matrixTransform(eleSvg.getScreenCTM().inverse());
}
@netsi1964
netsi1964 / funheadlines.js
Created March 10, 2022 20:55
Make news fun again
var tags = Array.from(document.querySelectorAll('*')).filter(ele => !/^(a|script|iframe|title|meta|head|body|style|html|link|svg|path|g|button|img|picture|ol|ul|source|nav)$/ig.exec(ele.tagName));
var temp = tags.reduce((sum, curr) => {
const tag = curr.tagName;
const len = curr.textContent.length;
if (sum[tag]) {
sum[tag].len += len;
sum[tag].count++;
} else {
sum[tag] = { len, count:1};
}
@netsi1964
netsi1964 / RawHTML.js
Created August 22, 2017 06:30
RawHTML: ReactJS pure component to render HTML
const RawHTML = ({children, className = ""}) =>
<div className={className} dangerouslySetInnerHTML={{ __html: children.replace(/\n/g, '<br />')}} />
@netsi1964
netsi1964 / javascriptLocalstorageToDo.js
Created October 16, 2012 06:41
javascript localstorage toDo list
/****
Sten Hougaard, @netsi1964, Localstorage items
Ver 0.98, not fully tested
Please note: Do not support storing of objects with functions
Added option to parse key (when using more than one localstorage)
Changed names from toDos to items, more generic
****/
var items;
if (typeof localStorage === 'undefined' ) {