Skip to content

Instantly share code, notes, and snippets.

View rarous's full-sized avatar
💭
I may be slow to respond.

Aleš Roubíček rarous

💭
I may be slow to respond.
View GitHub Profile
@rarous
rarous / wc.js
Created October 14, 2024 17:06
Isomorphic Web Component definition Live Template for Webstorm
/**
* @param {Window} globalScope
* @return {typeof $NAME$}
*/
export function def$NAME$({ HTMLElement, customElements }) {
class $NAME$ extends HTMLElement {
static register(tagName = "$TAG$") {
this.tagName = tagName;
customElements.define(tagName, this);
}
@rarous
rarous / s3-sync.js
Created November 3, 2023 02:12
Efficient S3 sync based on content hash stored in metadata
import { S3 } from "@aws-sdk/client-s3";
import { partition } from "@thi.ng/transducers";
import md5File from "md5-file";
import mimetypes from "mime-types";
import fs from "node:fs";
import path from "node:path";
function* getFiles(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const file of entries) {
display_information:
name: CircleCI
description: CircleCI status bot
background_color: "#292929"
features:
bot_user:
display_name: CircleCI
always_online: false
oauth_config:
scopes:
/* https://go.tacodewolff.nl/minify */
enScroll=!1;const lStor=localStorage,sStor=sessionStorage,doc=document,docEl=document.documentElement,docBody=document.body,docLoc=document.location,w=window,s=screen,nav=navigator||{};function a(){const k="G-XXXXXXXXXX",t=()=>Math.floor(Math.random()*1e9)+1,n=()=>Math.floor(Date.now()/1e3),y=()=>(sStor._p||(sStor._p=t()),sStor._p),v=()=>t()+"."+n(),p=()=>(lStor.cid_v4||(lStor.cid_v4=v()),lStor.cid_v4),m=lStor.getItem("cid_v4"),u=()=>m?void 0:enScroll==!0?void 0:"1",l=()=>(sStor.sid||(sStor.sid=n()),sStor.sid),d=()=>{if(!sStor._ss)return sStor._ss="1",sStor._ss;if(sStor.getItem("_ss")=="1")return void 0},r="1",h=()=>{if(sStor.sct)if(enScroll==!0)return sStor.sct;else x=+sStor.getItem("sct")+ +r,sStor.sct=x;else sStor.sct=r;return sStor.sct},e=docLoc.search,f=new URLSearchParams(e),a=["q","s","search","query","keyword"],g=a.some(t=>e.includes("&"+t+"=")||e.includes("?"+t+"=")),i=()=>g==!0?"view_search_results":enScroll==!0?"scroll":"page_view",b=()=>enScroll==!0?"90":void
/**
* Converts Alpha‑2 country code (ISO 3166) to unicode flag emoji
* @param {String} countryCode
* @returns {String}
*/
export function flagEmoji(countryCode) {
const s = countryCode.toUpperCase();
return String.fromCodePoint(
127397 + s.charCodeAt(0),
127397 + s.charCodeAt(1)
/**
* @param {Element} el
*/
function parse(el) {
const parsedJSON = JSON.parse(el.textContent);
if (Array.isArray(parsedJSON)) return parsedJSON;
return [parsedJSON];
}
/**
@rarous
rarous / web.js
Created July 18, 2022 09:19
Reads fetched response with declared charset
/**
* Reads the response text in given text encoding.
* When charset isn't defined on `content-type` header it falls back to `utf-8`.
* @param {Response} resp
* @returns {string}
*/
async function readTextResponse(resp) {
const contentType = resp.headers.get("content-type");
const [, charset] = contentType?.split("charset=");
const decoder = new TextDecoder(charset ?? "utf-8");
@rarous
rarous / K2.xml
Last active June 15, 2022 14:36 — forked from monk-topmonks/K2.xml
Serato DJ MIDI mapping for 4 decks (3124) with two K2s
<midi app=" 2.5.12.690">
<control channel="14" event_type="Note On" control="20">
<userio event="click">
<play deck_set="Default" deck_id="1" slot_id="0">
<translation action_on="press" behaviour="toggle"/>
</play>
</userio>
<userio event="output">
<play deck_set="Default" deck_id="1" slot_id="0">
<translation action_on="any">
@rarous
rarous / csv-formatter.mjs
Last active May 4, 2022 07:38
CSV formater
const reorderFields = headers => row => headers.map(key => row[key]);
const rowFormatter = row =>
row.map(v => `"${String(v).replaceAll(`"`, `""`)}"`).join(",");
const arrayToCsv = data => data.map(rowFormatter).join("\r\n");
export function writeToString(rows, options) {
const { headers, transform = x => x } = options;
const data = rows.map(transform).map(reorderFields(headers));
return arrayToCsv([headers].concat(data));
}
export function registrationNumberValidator(regNr) {
if (!regNr || (typeof regNr !== "string") || regNr.length !== 8) return false;
const [n8, n7, n6, n5, n4, n3, n2, x] = regNr.split("").map(Number);
return (
x ===
(11 -
((8 * n8 + 7 * n7 + 6 * n6 + 5 * n5 + 4 * n4 + 3 * n3 + 2 * n2) % 11)) %
10
);
}