This file contains hidden or 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
// HTML to YAML Extractor and Updater | |
/** | |
* A tool to extract content from HTML, convert it to YAML, and update HTML content from YAML files. | |
*/ | |
import cheerio from "cheerio"; | |
import { promises as fs } from "fs"; | |
import path from "path"; | |
import yaml from "js-yaml"; |
This file contains hidden or 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
// This code sends a prompt to the OpenAI API and then outputs the response | |
// to the terminal and to a file. | |
// Setup: | |
// npm init -y && npm i dotenv node-fetch | |
// echo "OPENAI_API_KEY=sk-XXX" > .env | |
import fs from "fs"; | |
import fetch from "node-fetch"; | |
import * as dotenv from "dotenv"; |
This file contains hidden or 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
// alternative ip notations | |
// https://ma.ttias.be/theres-more-than-one-way-to-write-an-ip-address/ | |
// https://twitter.com/h43z/status/1618220318023364608 | |
dotNotationToDec({ ip: "185.15.230.26" }); // liip.ch; | |
dotNotationToDec({ prefix: "185.", ip: "15.230.26" }); | |
/* | |
output: | |
dec http://3104826906/ |
This file contains hidden or 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
// convert .webm to .mp4 and remove audio | |
// ffmpeg -i in.webm -vcodec h264 -an out.mp4 | |
function dateString() { | |
const now = new Date(); | |
return ( | |
now.getUTCFullYear() + | |
"-" + | |
("0" + (now.getUTCMonth() + 1)).slice(-2) + |
This file contains hidden or 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
// This is a basic templating function. It replaces any {{key}} in the | |
// string with the corresponding value in data. If no data is provided, | |
// then the template is returned as-is. | |
// | |
// Example: | |
// template("Hello, {{name}}!", { name: "John" }) → "Hello, John!" | |
// template("Hello, {{name}}!") → "Hello, {{name}}!" | |
export function template(string, data = {}) { | |
let out = string; |
This file contains hidden or 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
const at = (arr, n) => { | |
const offset = Math.abs(n) % arr.length; | |
if (n >= 0) { | |
return arr[n % arr.length]; | |
} else { | |
return arr[(arr.length - offset) % arr.length]; | |
} | |
}; |
This file contains hidden or 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
export function escapeHtml(unsafe) { | |
return unsafe | |
.replace(/&/g, "&") | |
.replace(/</g, "<") | |
.replace(/>/g, ">"); | |
} | |
export function style(obj) { | |
return Object.entries(obj) | |
.map( |
This file contains hidden or 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
const doc = ` | |
## Vue-Splitter | |
It is a tool to split a folder with .vue files into three files (.split.js/.split.scss/.split.vue) | |
and merge them back together. Ideal for refactoring code with external tools that don't know .vue files. | |
## ⚠️ CAUTION | |
⚠️⚠️⚠️ Make sure you have a proper copy (git) of your code before you run this tool. |
This file contains hidden or 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://gist.github.com/signalwerk/eadabea1fc42795ed8af2882693d20e1 | |
* | |
* Return the value at `path` in `object` | |
* @param {Object} object | |
* @param {string|array} path | |
* @returns {*} value if found otherwise undefined | |
*/ | |
export const get = (object, path) => { | |
let parts = path; |
This file contains hidden or 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
// get an url in node without additional packages | |
const https = require("https"); | |
function httpRequest(method = "get", url, body = null) { | |
if (!["GET", "POST", "HEAD"].includes(method.toUpperCase())) { | |
throw new Error(`Invalid method: ${method}`); | |
} | |
let urlObject; |