Skip to content

Instantly share code, notes, and snippets.

View laphilosophia's full-sized avatar

Erdem Arslan laphilosophia

View GitHub Profile
@laphilosophia
laphilosophia / safe-list.ts
Last active January 27, 2026 10:45
SafeList - Defensive collection for untrusted user code
/**
* @fileoverview SafeList v4.0 - Production-Grade Immutable Chunked List
* @description Zero-cast implementation, strict type safety, power-of-2 optimizations
*/
// =============================================================================
// BRANDED TYPES & CONFIGURATION
// =============================================================================
declare const ListIdBrand: unique symbol
@laphilosophia
laphilosophia / persistent-secure-task-scheduler.js
Created January 27, 2026 08:17
Persistent secure task scheduler in javascript
const fs = require('fs')
const path = require('path')
const crypto = require('crypto')
class PersistentSecureTaskScheduler {
constructor(options = {}) {
this.tasks = new Map()
this.metrics = new Map()
this.auditLog = options.auditLog || console.log
this.circuitBreakerThreshold = options.circuitBreakerThreshold || 5

Jittered Tick Scheduler

interface TickSchedulerConfig {
  auditLog: (entry: AuditEntry) => void
  onTaskFailure?: (id: string, error: Error, consecutive: number) => void
}

class JitteredTickScheduler {
  private tasks = new Map<string, ScheduledTask>()
@laphilosophia
laphilosophia / db.json
Last active November 21, 2025 15:03
{
"blocks": [
{
"id": 1,
"doorNumber": "5",
"floorNumber": 11,
"blockNumber": "D2",
"apartmentType": "5+1",
"size": 117,
"fullName": "Tunç Okumuş",
@laphilosophia
laphilosophia / immutable.ts
Created December 30, 2022 12:34
simple immutable class library
export class ImmutableUtility<T> {
#draft: any
constructor(array: Array<T>) {
if (array.length === 0) {
throw new Error('Out of bounds...')
}
this.#draft = [...array]
}
@laphilosophia
laphilosophia / removeItem.ts
Created December 30, 2022 12:33
Simple, shallow checked, remove item from array
export function removeItem<T>(array: Array<T>) {
let cache = array
let count = array.length
let checkArrayContains = (() => Object.is(cache[0], cache[count - 1]))()
let findCurrentIndex = (key: any) => cache.findIndex((item: any) => item === key)
let immutableSlice = (start: number) => [...cache.slice(0, start), ...cache.slice(start + 1)]
if (!Array.isArray(cache)) throw new Error('type error! [array] expected!')
@laphilosophia
laphilosophia / count.ts
Created December 29, 2022 16:14
Simple, yet elegant python like string count
export default function count(
str: string,
{
trim,
strict,
custom,
}: {
trim?: boolean
strict?: boolean
custom?: RegExp
@laphilosophia
laphilosophia / areEquivalent.js
Created December 10, 2021 10:55 — forked from DLiblik/areEquivalent.js
Fast JS function for testing if Javascript values/objects are equivalent or equal - guards against circular references, prioritizes speed.
/**
Compares two items (values or references) for nested equivalency, meaning that
at root and at each key or index they are equivalent as follows:
- If a value type, values are either hard equal (===) or are both NaN
(different than JS where NaN !== NaN)
- If functions, they are the same function instance or have the same value
when converted to string via `toString()`
- If Date objects, both have the same getTime() or are both NaN (invalid)
- If arrays, both are same length, and all contained values areEquivalent
@laphilosophia
laphilosophia / promise_map.js
Created May 4, 2021 12:29 — forked from tokland/promise_map.js
Execute promises sequentially (one at at a time) and return array with the results
function promiseMap(inputValues, mapper) {
const reducer = (acc$, inputValue) =>
acc$.then(acc => mapper(inputValue).then(result => acc.push(result) && acc));
return inputValues.reduce(reducer, Promise.resolve([]));
}
/* Example */
const axios = require('axios');
@laphilosophia
laphilosophia / fpsMeter.js
Created December 21, 2020 18:21 — forked from capfsb/fpsMeter.js
JavaScript FPS meter - Calculating frames per second
fpsMeter() {
let prevTime = Date.now(),
frames = 0;
requestAnimationFrame(function loop() {
const time = Date.now();
frames++;
if (time > prevTime + 1000) {
let fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );
prevTime = time;