Skip to content

Instantly share code, notes, and snippets.

@mallendeo
mallendeo / 100.conf
Last active March 13, 2025 21:19
Windows 11 Gaming VM on Proxmox VFIO
##/etc/pve/qemu-server/100.conf
##Network and disks not included in this example
##Set halt_poll_ns
#set_halt_poll 0
##CPU pinning
#cpu_taskset 1-7
#assign_interrupts --sleep=10s 1-7 --all
agent: 1
@mallendeo
mallendeo / README.md
Created May 8, 2021 20:55
Tasmota RGB

19812VER:F rgb

@mallendeo
mallendeo / table-to-json.ts
Last active February 5, 2021 23:02
HTML Table to JSON
import { camelCase } from 'change-case'
// $: cheerio object
const tableToJson = ($, table) => {
const fields = $(table)
.find('thead tr th')
.map((_, el) => $(el).text().trim())
.get()
const rows = $(table)
.find('tbody tr')
@mallendeo
mallendeo / helpers.ts
Last active February 5, 2021 20:26
Simple helper functions
import * as crypto from 'crypto'
import iconv from 'iconv'
import ms from 'ms'
export const waitFor = (ms = 500): Promise<void> => new Promise((r) => setTimeout(r, ms))
export const cleanText = (text: string): string => text.trim().replace(/[\r\n\t®]/gi, '')
export const cleanPrice = (price: string): number => parseInt(price.replace(/[\$\.]/g, ''))
@mallendeo
mallendeo / logger.ts
Created February 1, 2021 23:35
Example winston configuration with file rotation
import 'winston-daily-rotate-file'
import stringify from 'json-stringify-safe'
import path from 'path'
import winston from 'winston'
import config from '@/config'
const dailyRotateTransport = new winston.transports.DailyRotateFile({
filename: path.join(config.logBase, `${config.appName}-%DATE%.log`),
@mallendeo
mallendeo / custom-error.ts
Created February 1, 2021 23:33
Custom error class for express/general use
import { NextFunction, Request, Response } from 'express'
export class AppError extends Error {
status: number
slug: string
constructor(message: string, status: number, errSlug?: string) {
super(message)
this.name = this.constructor.name
@mallendeo
mallendeo / amqplib.ts
Created February 1, 2021 23:30
RabbitMQ lib example
import amqplib, { Channel, ConsumeMessage, Replies } from 'amqplib'
import isFunction from 'lodash/isFunction'
import config from '../config'
import { logger } from './logger'
const { user, password, host } = config.amqplib
const url = user && password ? `amqp://${user}:${password}@${host}` : `amqp://${host}`
export const open = amqplib.connect(url)
@mallendeo
mallendeo / redis.ts
Last active February 1, 2021 23:29
Custom ioredis based redis client
import Redis, { RedisOptions } from 'ioredis'
import ms from 'ms'
import config from '../config'
import { logger } from './logger' // winston, pino, ...
export const toSeconds = (time: string | number): number =>
typeof time === 'number' ? time : ms(time) / 1000
export interface CustomRedis extends Redis.Redis {
@mallendeo
mallendeo / react-native-apk.sh
Created January 11, 2021 15:34
Build react-native release apk for android
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
cd android && ./gradlew assembleRelease; cd ..
cp android/app/build/outputs/apk/release/app-release.apk ~/Desktop
@mallendeo
mallendeo / remove-pdf-protection.md
Last active January 4, 2021 06:20
Remove PDF protection using Ghostscript

Remove the owner password from an encrypted PDF using Ghostscript

Note: you still need to know the password for opening the file

brew install ghostscript # on macOS
gs -q -dNOPAUSE -dBATCH -dPrinted=true -dShowAnnots=false -sDEVICE=pdfwrite -sPDFPassword=YOUR_PDF_PASSWORD -sOutputFile=unlocked.pdf -f locked.pdf