Skip to content

Instantly share code, notes, and snippets.

View erdesigns-eu's full-sized avatar
$ root@erdesigns

ERDesigns - Ernst Reidinga erdesigns-eu

$ root@erdesigns
View GitHub Profile
import fetch from 'node-fetch';
/**
* Youtube Resolver Parameters
* @interface YoutubeResolverParams
* @property {string} url - Youtube URL (https://www.youtube.com/watch?v=VIDEO_ID)
* @property {string} videoId - Youtube Video ID
*/
interface YoutubeResolverParams {
url?: string;
@erdesigns-eu
erdesigns-eu / DDPClient.ts
Last active January 3, 2025 09:06
DDP Client in Typescript
// DDPClient.ts
import { EventEmitter } from 'events';
/**
* Enum representing the different types of DDP messages.
* @property CONNECT - Client initiates a connection.
* @property CONNECTED - Server acknowledges a successful connection.
* @property FAILED - Server indicates a failed connection attempt.
* @property SUBSCRIBE - Client subscribes to a publication.
@erdesigns-eu
erdesigns-eu / ShellcodeCreator.pas
Last active December 19, 2024 11:59
Advanced Shell code generator in Delphi
unit ShellcodeCreator;
interface
uses
SysUtils, Windows, TypInfo, Classes, ZLib, System.Hash, System.Encryption;
/// <summary>
/// Shellcode creator for dynamically generating shellcode for function calls.
/// Supports x86, x64, and ARM architectures with parameter and return type handling.
@erdesigns-eu
erdesigns-eu / SysCallExecutor.pas
Created December 19, 2024 10:19
Cross-Platform System Call Executor (x86, x64, ARM) in Delphi
unit SysCallExecutor;
interface
uses
Windows, SysUtils;
type
TSysCallExecutor = class
private
@erdesigns-eu
erdesigns-eu / runtimeRequire.ts
Created December 17, 2024 13:43
Runtime require function to fix loading native .node modules when using PKG
/**
* This function is used to load the native .node module. Since webpack replaces the native require function,
* we need to get the original require function from the global scope.
*
* Found this code here: https://github.com/prebuild/node-gyp-build/blob/master/node-gyp-build.js
*/
// @ts-ignore
const runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
const nativeModule = runtimeRequire('./path/to/module.node');
@erdesigns-eu
erdesigns-eu / getImageType.ts
Created December 2, 2024 13:40
Get the image type from a buffer
/**
* Get the type of an image.
* @param image The image as a buffer.
* @returns The type of the image.
*/
export function getImageType(image: Buffer): Promise<{ mimeType: string, extension: string }> {
return new Promise((resolve, reject) => {
if (image[0] === 0xFF && image[1] === 0xD8 && image[2] === 0xFF) {
resolve({
mimeType: 'image/jpeg',
@erdesigns-eu
erdesigns-eu / useWebWorker.ts
Last active January 3, 2025 09:05
Custom React Hook to run a task in a WebWorker and get the result back in a Promise.
import { useState, useEffect, useCallback, useRef } from 'react';
/**
* WebWorker status flags
* - idle: The worker is not running any task
* - working: The worker is running a task
*/
type WebWorkerStatus = 'idle' | 'working';
/**
@erdesigns-eu
erdesigns-eu / totp.ts
Last active January 3, 2025 09:06
Time-based one-time password in Typescript
import { randomBytes, createHmac, timingSafeEqual } from 'crypto';
/**
* Charset for base32 encoding
* @see https://en.wikipedia.org/wiki/Base32
* @see https://tools.ietf.org/html/rfc4648
*/
const base32Charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
/**
* Number of digits in TOTP token
@erdesigns-eu
erdesigns-eu / makeResolvablePromise.ts
Created November 14, 2024 10:00
Utility function to create a promise, and return the promise + reject + resolve
type ResolvablePromise<Value = void> = {
promise: Promise<Value>;
resolve: (value: Value | PromiseLike<Value>) => void;
reject: (reason?: any) => void;
};
export function makeResolvablePromise<Value = void>(): ResolvablePromise<Value> {
let resolveFunction: (value: Value | PromiseLike<Value>) => void;
let rejectFunction: (reason?: any) => void;
@erdesigns-eu
erdesigns-eu / BLEServer.cpp
Created August 8, 2024 12:02
Updated BLEServer
// BLEServer.cpp
//
// Copyright (C) 2024, Ernst Reidinga
// Copyright (C) 2017, Uri Shaked
//
#include "stdafx.h"
#include <iostream>
#include <Windows.Foundation.h>
#include <Windows.Devices.Bluetooth.h>