Skip to content

Instantly share code, notes, and snippets.

View alshdavid's full-sized avatar

David Alsh alshdavid

View GitHub Profile
@alshdavid
alshdavid / index.js
Created March 5, 2024 09:21
Deno in rust
function echo(value) {
Deno.core.print("called with " + value)
}
Deno.core.ops.op_register_func(echo)
@alshdavid
alshdavid / install-zenith.bash
Created February 28, 2024 22:28
Install Zenith Binary
set -ev
rm -rf $HOME/.local/zenith
mkdir -p $HOME/.local/zenith/bin
wget https://github.com/bvaisvil/zenith/releases/latest/download/zenith.x86_64-unknown-linux-musl.tgz -O $HOME/.local/zenith/bin/zenith.tgz
tar -C $HOME/.local/zenith/bin -xzf $HOME/.local/zenith/bin/zenith.tgz
rm -rf $HOME/.local/zenith/bin/zenith.tgz
chmod +x $HOME/.local/zenith/bin/zenith
@alshdavid
alshdavid / increase-thai-font-size.mjs
Last active January 15, 2024 03:40
increase thai font size
(() => {
// Styles to apply
const styles = {
fontSize: '30px',
fontFamily: '"Noto Serif Thai", serif',
}
// Add fonts if they don't exist
const font_url = "https://fonts.googleapis.com/css2?family=Noto+Serif+Thai&display=swap";
if (!document.head.querySelector(`link[href="${font_url}"]`)) {
@alshdavid
alshdavid / README.md
Last active November 17, 2023 21:25
CBA PDF statement converter to PDF or CSV
@alshdavid
alshdavid / tsconfig.strictest.json
Created July 12, 2023 23:41
Strictest TypeScript config posible
{
"compilerOptions": {
// Resolution (adjust to use case)
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "Node16",
"lib": ["ESNext"],
"types": ["node"],
// Super strict

Jest Dynamic Mock

Used to recursively dynamically generate an object where the properties are jest.fn() functions.

Behind the scenes it uses a JavaScript Proxy to detect if a property on the created object is being accessed or being invoked. If it's being invoked it generates a jest.fn() and uses that, if it's being accessed it creates a new mock proxy. This allows for mocks to be generated for objects dynamically and deeply.

// Source of https://www.npmjs.com/package/physical-cpu-count
'use strict'
const os = require('os')
const childProcess = require('child_process')
function exec (command) {
const output = childProcess.execSync(command, {encoding: 'utf8'})
return output
@alshdavid
alshdavid / local-storage-async.js
Created February 24, 2023 11:02
LocalStorage API powered by Indexeddb
class LocalStorageAsync {
static DatabaseKey = 'LocalStorageAsync.DatabaseKey'
static DatabaseStoreKey = 'LocalStorageAsync.DatabaseStoreKey'
#hasLoaded
constructor() {
this.#hasLoaded = new Promise((resolve, reject) => {
let dRequest = indexedDB.deleteDatabase(LocalStorageAsync.DatabaseKey)
dRequest.onerror = function() {
@alshdavid
alshdavid / README.md
Created November 4, 2022 07:13
Simple argument parsing function for Node.js

Usage

const args = parseArgs(process.argv.splice(2))
const args = parseArgs(['--foo', 'one'])

console.log(args.foo) // ['one']