Skip to content

Instantly share code, notes, and snippets.

// Remove articles with certain stop words, on a website.
//
// How? This script can be pasted into the developer console of a browser.
// When you run it (normally just by hitting ENTER) it blurs the according articles.
//
// What else? You can add or remove stop words that are used to find the articles
// with the according words.
const stopWords = ['corona', 'covid', 'pandemie', 'trump', 'biden'];
// Variant 1
// Works as expected.
// I did:
// - select the first ocurence of `() => { console.log(); }` in line 8 AND
// - call WebStorm action "Introduce Variable"
// Webstorm offers me to replace all 3 places where the selected code is used (line 8, 10 and 13).
someFn({log: () => { console.log(); }});
const fn1 = () => {
someFn({log: () => { console.log(); }});

Keybase proof

I hereby claim:

  • I am wolframkriesing on github.
  • I am wolframkriesing (https://keybase.io/wolframkriesing) on keybase.
  • I have a public key ASB_crowHEbZr-XwQ2gGxlSP_c90Kp6kEhQAhSQq6qcLbgo

To claim this, I am signing this object:

const validateBranching = ({ name, type, email, phone }) => {
if (!isValidName(name))
return Required('name');
if (type === 'email') {
if (!isValidEmail(email))
return InvalidEmail(email);
if (phone && !isValidPhone(phone))
return Optional(InvalidPhone(phone));
return { type, name, email, phone };
@wolframkriesing
wolframkriesing / limited-scope.js
Created October 25, 2019 09:01
using braces to limit scopes
const findUser () => {
{
const userOrError = findUserInCache();
if (userOrError instanceof Error) return userOrError;
if (userOrError instanceof User) return userOrError;
}
{
const userOrError = findUserInDb(); // reusing `userOrError` inside the same fn
if (userOrError instanceof Error) return userOrError;
if (userOrError instanceof User) return userOrError;
@wolframkriesing
wolframkriesing / jscc18-webcomponents-from-scratch.html
Created August 10, 2018 15:45
The "web components from scratch" session at #jscc18, JSCraftCamp
<!DOCTYPE html>
<html>
<head>
<title>WebComponent from Scratch</title>
<script type="module" src="myH1.js"></script>
</head>
<body>
<style>
a {
color: orange;
@wolframkriesing
wolframkriesing / more-h1.html
Created August 5, 2018 12:00
The "extended" H1 we built at busconf 2018
<!DOCTYPE html>
<html>
<head>
<title>WebComponent from Scratch</title>
</head>
<body>
<h1>WebComponent from Scratch</h1>
<h1 is="my-h1" linkable="1" hash="some-thing">something</h1>
const tap = require('tap');
const test = tap.test;
function findImageDimensions() {
return {width: 100, height: 100};
}
// this FAILS
test('Find image dimensions', (t) => {
t.test('if requested size matches, return it', (t) => {
@wolframkriesing
wolframkriesing / async-await-in-tests.js
Created June 3, 2016 06:40
async+await for test-readability
// This code shows two ways of writing the same test.
// 1) Using a promise-test-helper names hamjest, which makes testing promises simple.
//
// This uses the mocha feature that we return a promise and by that
// the test outcome is determined, therefore the `return` is needed.
// Hamjest's `promiseThat` is awesome for testing with promises,
// it highlights that we are inside a promise, but handles all magic, such
// as the reject case, etc.
import {
export const buildFunctionSpy = ({ returnValue = void 0 } = {}) => {
const spy = (...args) => {
spy.wasCalled = true;
spy.lastCallArgs = args;
spy.allCallsArgs.push(args);
spy.callCount++;
return returnValue;
};
spy.wasCalled = false;
spy.lastCallArgs = null;