This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Limit the number of concurrent promises | |
* @param promises The array of promise functions to execute | |
* @param maxConcurrent The maximum number of promises to execute concurrently | |
* @returns A promise that resolves with an array of results | |
*/ | |
export const limitConcurrentPromises = async <T>(promises: (() => Promise<T>)[], maxConcurrent: number): Promise<T[]> => { | |
// Array to store the results of each promise | |
const results: T[] = []; | |
// Array to keep track of the currently executing promises |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fetch from 'node-fetch'; | |
import fs from 'fs'; | |
/** | |
* OpenAI API key | |
* @see https://platform.openai.com/docs/quickstart | |
* @note Do not commit the API key to version control. | |
*/ | |
const apiKey = ''; // Add your OpenAI API key here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A callback function that is called when a value changes. | |
* @callback SubscriptionCallback | |
* @param {any} value The new value. | |
* @returns {void} | |
*/ | |
type SubscriptionCallback<T = any> = (value: T) => void; | |
/** | |
* A simple client-side storage class that uses localStorage to store values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Find all Vue components that match the given matcher and return them in an array. | |
* @param parent The parent component to search. | |
* @param matcher The matcher to use. | |
* @returns An array of components that match the given matcher. | |
*/ | |
export const findVueChildComponents = (parent: any, matcher: RegExp | String | undefined) => { | |
const found: any[] = []; | |
const root = parent.$.subTree; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Attrs = { | |
[key: string]: any; | |
}; | |
const h = (tag: string, attrs: Attrs, ...children: (Node | string)[]): HTMLElement => { | |
const elm = document.createElement(tag); | |
for (let key in attrs) { | |
if (key.startsWith('on')) { | |
const evtName = key.slice(2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type TokenType = 'KEYWORD' | 'IDENTIFIER' | 'NUMBER' | 'STRING' | 'OPERATOR' | 'DELIMITER' | 'EOF' | 'UNKNOWN' | 'PROCEDURE' | 'FUNCTION' | 'CONSTANT' | 'RECORD'; | |
class Token { | |
constructor(public type: TokenType, public value: string, public position: number, public line: number, public column: number) {} | |
} | |
class Lexer { | |
private pos: number = 0; | |
private line: number = 1; | |
private column: number = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In Belgium there is a possibility to have a prepaid smart meter for electricity. Fluvius has an app and webpage where you can see the details. | |
I wanted to incorporate this api into a dashboard for a client, so for this purpose i tried to fetch the data myself. Use this on you own risk! | |
I contacted fluvius to ask if i could access their api for this purpose, but i didnt get an answer. So im sharing it here for anyone else who likes to do the same. | |
GET /prepaid/api/prepaid-contracts HTTP/1.1 | |
Host: mijn.fluvius.be | |
X-Fluv-Prepaid-Identification-Code: <UNIQUE-PREPAID-CODE> | |
X-Fluv-Prepaid-Postal-Code: <ZIPCODE> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate a color based on letters. | |
export const generateColor = (letters) => { | |
// Generate a simple hash from a string | |
const getHashOfString = (str) => { | |
let hash = 0; | |
for (let i = 0; i < str.length; i++) { | |
hash = str.charCodeAt(i) + ((hash << 5) - hash); | |
} | |
hash = Math.abs(hash); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parseDFM = (text) => { | |
let result = null; | |
// Replace all returns with newlines | |
text = text.replace(/\r\n/g, '\n'); | |
text = text.replace(/\r/g, '\n'); | |
// Split into lines | |
const lines = text.split('\n'); | |
let currentComponent = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit untHTTPManager; | |
interface | |
uses | |
System.Classes, System.SysUtils, System.Generics.Collections, System.Threading, IdHTTP, IdSSLOpenSSL, | |
Winapi.Windows, Winapi.Messages; | |
type | |
THTTPThreadManager = class; |