Skip to content

Instantly share code, notes, and snippets.

Florian Klampfer qwtel

Block or report user

Report or block qwtel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 10.js
const nearestAsteroidsByAngle = pipe(
asteroids.filter(mkNe(laserPos)),
groupBy(mkCalcAngle(laserPos)),
mapValues(ps => ps.sort((p1, p2) => distToLaser(p1) - distToLaser(p2))),
intoMap(),
);
pipe(
cycle([...nearestAsteroidsByAngle.keys()].sort((a, b) => a - b)),
skipWhile(a => a < -Math.PI/2),
View ParamsURL.js
export class ParamsURL extends URL {
constructor(href, params, origin = globalThis.location) {
super(href, origin);
if (params) {
this.search = new URLSearchParams([...this.searchParams, ...Object.entries(params)]);
}
}
}
View urlWithParams.js
export const urlWithParams = (url, params) => {
const u = new URL(url, global.location.origin)
if (params) {
u.search = new URLSearchParams([...u.searchParams, ...Object.entries(params)])
}
return u.href
}
@qwtel
qwtel / JSONRequest.js
Last active Oct 27, 2019
Subtypes of the browser's own Request and Response types adopted for JSON objects.
View JSONRequest.js
export class JSONRequest extends Request {
constructor(input, init, replacer, space) {
const { headers: h, body: b, ...rest } = init || {};
const body = b ? JSON.stringify(b, replacer, space) : null;
const headers = new Headers(h);
headers.set('Accept', 'application/json, text/plain, */*');
if (body) headers.set('Content-Type', 'application/json;charset=UTF-8');
@qwtel
qwtel / README.md
Last active Sep 8, 2019
Returns the first promise that resolves with a truthy value, or undefined if all promises resolve with a nullish value.
View README.md

Returns the first promise that resolves with a truthy value, or undefined if all promises resolve with a nullish value.

Note that this inherits the behavior of Promise.race, where the returned promise rejects as soon as one input promise rejects.

Example use case: Getting a cached response from a number of caches, without resorting to a lookup in all caches via caches.match:

View replacing-cryptojs-with-web-cryptography-for-aes.js
import md5 from "js-md5";
import { base64ToUint8Array, splitUint8Array, concatUint8Arrays } from "./utils";
const HEAD_SIZE_DWORD = 2;
const SALT_SIZE_DWORD = 2;
export async function decryptCryptoJSCipherBase64(
cryptoJSCipherBase64,
password,
View keybase.md

Keybase proof

I hereby claim:

  • I am qwtel on github.
  • I am qwtel (https://keybase.io/qwtel) on keybase.
  • I have a public key ASCbFur24236CAj1oGXKHjjTVGaT35JcTLQNXvXUFG7aOwo

To claim this, I am signing this object:

View fetch-rx.js
function fetchRx(url, options) {
const controller = new AbortController();
const { signal } = controller;
return Observable.create(observer => {
fetch(url, { signal, ...options })
.then(x => observer.next(x))
.catch(x => observer.error(x))
.finally(() => observer.complete())
return () => controller.abort();
});
View sigV4Client.js
/*
* Copyright (c) 2018 Florian Klampfer <https://qwtel.com/>
*
* This software uses portions of `sigV4Client.js`,
* which is Apache-2.0 licensed with the following copyright:
*
* > Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Changes:
* * Replaced "crypto-js" with Web Cryptography API
@qwtel
qwtel / jsx-create-element.js
Last active Dec 6, 2017
Patches the default document.createElement function to follow the JSX/React.createElement function signature.
View jsx-create-element.js
var createElement = document.createElement.bind(document);
function appendChild(child) {
this.appendChild(
child instanceof Element ? child : document.createTextNode(child)
);
}
document.createElement = function(tagName, attrs, children) {
var el = createElement(tagName);
You can’t perform that action at this time.