Skip to content

Instantly share code, notes, and snippets.

View kadiks's full-sized avatar

Jénaïc Cambré kadiks

View GitHub Profile
@kadiks
kadiks / cmd.js
Created July 5, 2023 11:49
Basic CLI
#!/usr/bin/env node
const { mkdirSync, writeFileSync } = require('node:fs');
const params = process.argv.slice(2);
if (params.length === 0) {
console.log('No arguments provided');
process.exit(1);
}
@kadiks
kadiks / fastfinger.js
Created June 6, 2023 08:39
Impress your friends by typing fast in 10fastfingers.com
function delay(ts = 100) {
return new Promise((resolve) => {
setTimeout(resolve, ts)
})
}
async function typeWord({ word, delayMs = 300 } = {}) {
if (!word) {
console.log('Word is undefined')
// @ts-nocheck
import * as ts from "ts-morph"
import * as fs from "fs"
import * as path from "path"
import * as glob from "glob"
import { exec } from "child_process"
import slugify from "slugify"
const project = new ts.Project({
tsConfigFilePath: "./tsconfig.json",
@kadiks
kadiks / generateSwatch.js
Last active February 1, 2023 13:48
Dynamic palette on Next.js
const Spline = require("cubic-spline");
const tinycolor = require("tinycolor2");
function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
function generateSwatch(lightColor, seedColor, darkColor, hueInvariance) {
const light = tinycolor(lightColor);
const seed = tinycolor(seedColor);
@kadiks
kadiks / get-definition.js
Created August 1, 2022 18:14
Get the french definition of a word
import {load} from 'cheerio';
const getDefinition = async (word) => {
const url = `https://fr.wiktionary.org/wiki/${word}`;
// fetch with Node 18+ (or use Axios)
const response = await fetch(url);
const html = await response.text();
const $ = load(html);
@kadiks
kadiks / index.js
Last active July 17, 2022 01:46
Download YouTube playlists (2022)
// Installation
// -
// mkdir yt_download_playlist
// cd yt_download_playlist
// mkdir download
// npm init -y
// npm install puppeteer
// npm install ytdl-core
// touch index.js
// Related to François' question on this video: https://www.youtube.com/watch?v=ThcV5bW62nc
const generateQuestion = (countries) => {
const randomIndex = Math.floor(Math.random() * countries.length);
const country = countries[randomIndex];
const possibilities = [];
const selectedIndexes = []; // set of indexes of countries that are selected
while (possibilities.length < 3) {
@kadiks
kadiks / react-vue-comparison.js
Last active May 31, 2022 16:15
CLI lighthouse comparison between React & Vue doc websites
const lighthouse = require("lighthouse");
const chromeLauncher = require("chrome-launcher");
const runReport = async (url) => {
const chrome = await chromeLauncher.launch({
chromeFlags: ["--headless"],
});
const options = { output: "json", port: chrome.port };
const runnerResult = await lighthouse(url, options);