Skip to content

Instantly share code, notes, and snippets.

@felladrin
felladrin / index.cjs
Created April 1, 2024 10:14
Express HTTPS server running with self signed certificate generated with JavaScript
const fs = require("fs");
const https = require("https");
const express = require("express");
const forge = require("node-forge");
function generateCert(options) {
const keys = forge.pki.rsa.generateKeyPair(2048);
const cert = forge.pki.createCertificate();
cert.publicKey = keys.publicKey;
cert.serialNumber = "01";
@felladrin
felladrin / example.js
Last active March 28, 2024 09:40
Knowing if a number is odd in JavaScript without using division.
import { isOdd } from "./isOdd.mjs";
isOdd(7); // returns true
isOdd(8); // returns false
isOdd(9); // returns true
@felladrin
felladrin / getLinkedinArticles.js
Created May 25, 2023 12:10
JavaScript to list the articles you published on LinkedIn. Read more at https://learn.microsoft.com/en-us/linkedin/
const accessToken = 'YOUR_LINKEDIN_ACCESS_TOKEN';
async function getLinkedinArticles() {
const response = await fetch(
`https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,articles)`,
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'cache-control': 'no-cache',
},
@felladrin
felladrin / followGitHubUsers.js
Created April 13, 2023 12:45
DevTools script: Follow a list of GitHub users
/** @see https://docs.github.com/en/rest/users/followers?apiVersion=2022-11-28#follow-a-user */
(async () => {
// Generate a fine-grained token with the following "Followers" scope (read/write) at https://github.com/settings/tokens
const token = "YOUR_GITHUB_TOKEN";
const usernames = ["XXX", "YYY", "ZZZ"];
const headers = {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${token}`,
@felladrin
felladrin / index.ts
Last active February 14, 2023 20:02
Example of a pagination middleware using 'node-fetch' and 'restana'.
import fetch from "node-fetch";
import restana from "restana";
const service = restana();
const pageSize = process.env.PAGE_SIZE ? parseInt(process.env.PAGE_SIZE) : 5;
const port = process.env.PORT ? parseInt(process.env.PORT) : 3000;
const topStoriesResponse = await fetch(
@felladrin
felladrin / index.html
Created November 26, 2022 00:23
PeerJS Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PeerJS</title>
</head>
<body>
<script src="https://unpkg.com/peerjs@1.3.2/dist/peerjs.min.js"></script>
@felladrin
felladrin / js13k-2d.d.ts
Created August 21, 2022 16:52
TypeScript declarations for "js13k-2d" (https://www.npmjs.com/package/js13k-2d)
declare module "js13k-2d" {
declare interface Point {
x: number;
y: number;
set(xy: number): void;
set(x: number, y: number): void;
}
declare interface Sprite {
position: Point;
alpha: number;
@felladrin
felladrin / index.html
Created February 6, 2022 02:51
Loading TypeScript module directly in the browser using 'ts-browser-klesun'. You can try it at https://mrdoob.com/projects/htmleditor/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/webextensions/console-panel/src/console-panel.css" />
<script src="https://cdn.jsdelivr.net/gh/webextensions/console-panel/src/console-panel.js"></script>
<script>
window.consolePanel.enable();
import { defineConfig } from "vite";
import { minifyHtml } from "vite-plugin-html";
import { viteSingleFile } from "vite-plugin-singlefile";
import { Packer, InputType, InputAction } from "roadroller";
export default defineConfig({
plugins: [
{
name: "roadroller",
async transformIndexHtml(html, context) {
@felladrin
felladrin / tools-for-development.md
Last active May 25, 2023 10:49
My Recent Dev Tools