Skip to content

Instantly share code, notes, and snippets.

View Goblinlordx's full-sized avatar
🐈
Possibly distracted by an infernal red dot

Benjamin Baldivia Goblinlordx

🐈
Possibly distracted by an infernal red dot
  • Tridge
  • Seoul, South Korea
View GitHub Profile
@Goblinlordx
Goblinlordx / convert.ts
Last active May 14, 2025 11:42
DBC Conversion
import { parse } from "csv-parse/sync"
import Dbc from "dbc-can"
import { Message } from "dbc-can/lib/dbc/Dbc"
import fs from "fs"
const INDEPENDENT_SIGNALS = parseInt("c0000000", 16)
const EXTENDED_FLAG = parseInt('80000000', 16)
const MAX_ID = parseInt('7FF', 16)
const MAX_EXTENDED_ID = parseInt('1fffffff', 16)
const parseId = (s: string) => {
@Goblinlordx
Goblinlordx / relay.go
Created April 13, 2025 21:37
RTP relay
package trackrelay
import (
"context"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/webrtc/v4"
)
@Goblinlordx
Goblinlordx / AsyncIterable.ts
Last active August 16, 2024 06:24
Transformable AsyncIterable Processor
function* range(max: number = Infinity, start: number = 0) {
for (let i = start; i < max; i++) yield i;
}
async function* asyncify<T>(items: Iterable<T>) {
for (const item of items) yield item;
}
class AlreadyProcessedError extends Error {}
@Goblinlordx
Goblinlordx / RateLimiter.ts
Created July 31, 2024 06:50
Token Bucket Rate Limiter
export class RateLimiter {
private maxCalls: number
private interval: number
private tokens: number
private lastRefill: number
private callQueue: Array<() => void>
constructor(callsPerSecond: number, initialTokens: number = 0) {
this.maxCalls = callsPerSecond
this.interval = 1000 / this.maxCalls
export function chunk(arr, size) {
const output = [];
for (let i = 0; i < arr.length; i += size) {
output.push(arr.slice(i, i + size));
}
return output;
}
@Goblinlordx
Goblinlordx / docker-compose.yaml
Last active July 15, 2024 03:31
Example docker compose for server
version: "3.3"
services:
traefik:
image: traefik:v2.5
container_name: traefik
restart: unless-stopped
ports:
- "80:80" # The HTTP port
- "443:443" # The HTTPS port
@Goblinlordx
Goblinlordx / heap.ts
Last active June 14, 2022 01:45
heap TS
export const min = (a: number, b: number) => a < b
export const max = (a: number, b: number) => a > b
type Comparetor<T> = (a: T, b: T) => boolean
export class Heap<T = number> {
private heap: T[] = []
constructor(private comp: Comparetor<T>) {}
private parent(i: number) {
@Goblinlordx
Goblinlordx / TaskManagement.md
Last active March 7, 2022 06:08
task management doc

Basic task initiation and monitoring

  1. Client calls BE and initiates a Task. BE responds with a task ID or an error. The task ID can optionally be used by client.
  2. Client can establish a channel to receive task updates and maintain a local cache of the current task states. When client initializes, it can retrieve a list of active tasks on the backend for the given user.

A more detailed flow showing the Client, BE, DB, and ExternalServices [![](https://mermaid.ink/img/pako:

@Goblinlordx
Goblinlordx / go-fs.go
Last active November 25, 2021 06:41
Go FS
package main
import (
"flag"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
)
@Goblinlordx
Goblinlordx / AsyncQueue.js
Created October 6, 2020 03:10
Restructuring of event task system
// Standalone queue
const AsyncQueue = () => {
let p = Promise.resolve();
return (...args) => {
p = p.then(createTask(...args));
return p;
};
}
// With existing queue data (q is existing data)