Skip to content

Instantly share code, notes, and snippets.

@lot224
lot224 / converter.js
Created December 7, 2022 17:38
Mongo c# driver ObjectId to Guid converter nodejs
const b64ToGuid = (b64) => {
const bytes = Buffer.from(b64, "base64");
bits = [];
bytes.forEach(byte => {
bits.push(byte.toString(16).padStart(2, '0'));
});
const data = bits.join("");
const parts = [];
parts.push(data.substring(0, 8).split("").reverse().join(""));
@lot224
lot224 / fetch.ts
Last active December 20, 2021 20:42
mockFetch - require in setup.js
export const hookFetch = global.fetch;
type collection = {
[key: string]: {
response: {
success?: unknown
error?: unknown
}
headers?: {
[key: string]: string
@lot224
lot224 / base64.ts
Created August 24, 2021 13:36
Shortens a guid from 36 characters to (22-24) characters
// Inspired By
// https://stackoverflow.com/questions/6213227/fastest-way-to-convert-a-number-to-radix-64-in-javascript
// Haven't Fully Tested or implemented in a prod environment
// Generate Random Value matching a guid
const Guid = (): string => {
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/gi, () => {
const crypto = require('crypto');
const id = crypto.randomBytes(16).toString("hex")[5];
// from: https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
const color = {
Reset : "\x1b[0m",
Bright : "\x1b[1m",
Dim : "\x1b[2m",
Underscore : "\x1b[4m",
Blink : "\x1b[5m",
Reverse : "\x1b[7m",
Hidden : "\x1b[8m",
@lot224
lot224 / main.js
Last active January 11, 2022 17:41
Flat Array of filenames to html tree structure.
const files = [
"path/1/pages/home.html",
"path/1/pages/about.html",
"path/1/pages/settings.html",
"path/1/pages/contact.html",
"path/1/assets/images/background.jpeg",
"path/1/assets/images/logo.png",
"path/1/assets/images/arrow-left.png",
"path/1/assets/images/arrow-right.png",
@lot224
lot224 / menu.js
Created November 1, 2019 15:32
nodejs simple file menu
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const cwd = process.cwd();
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const files = [];
const filterExtension = null; // ".json"
@lot224
lot224 / TTT2.html
Created October 7, 2019 05:11
Sam's TTT2.html
<!doctype html>
<html>
<head>
<title>Tic Tac Toe</title>
<style>
button {
font-size: 40px;
height: 100px;
width: 100px;
@lot224
lot224 / fileInput processing.html
Created July 29, 2019 20:05
Takes a Image uploaded via a FileInput element and resizes it, if it exceeds a certain size.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>FileInput -> Image -> Canvas -> Bytes</title>
</head>
@lot224
lot224 / discordWebHook.cs
Created March 6, 2019 18:33
An very basic example of a Webhook in C# to Discord.
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
namespace discordWebHook
{
class Program
{
private static HttpClient client;
{[
"Acme Corp.",
"Aperture Science",
"Armacham",
"Bartok Science",
"Benthic Petroleum",
"Biffco Enterprises",
"Big Kahuna Burger",
"Black Mesa",
"Blue Sunv",