Skip to content

Instantly share code, notes, and snippets.

View ErickWendel's full-sized avatar

Erick Wendel ErickWendel

View GitHub Profile
@ErickWendel
ErickWendel / cpu-profiling-and-snapshot-nodejs.js
Last active November 12, 2024 20:48
Examples of how to take the cpu profilling and snapshots on applications that need to be publicly accessible
import { Session } from 'inspector/promises';
import fs from 'fs';
import net from 'net';
let session;
const now = new Date();
const profileFile = `/src/${now.getTime()}.cpuprofile`;
function createTCPServer({
onStart,
@ErickWendel
ErickWendel / ingress-service-app-.yaml
Created June 22, 2024 20:22
example of using Kubernetes with traefik and lets encrypt to generate SSL Certificates (without the need of adding any additional cluster issuer)
apiVersion: v1
kind: Service
metadata:
name: app
namespace: default
spec:
selector:
app: app
ports:
- protocol: TCP
for i in *.ARW; do sips -s format jpeg $i --out "${i%.*}.jpg"; done
INPUT=demo.gif
OUTPUT=demo-1.gif
ffmpeg -hide_banner -v warning -i $INPUT -filter_complex "[0:v] scale=320:-1:flags=lanczos,split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse" $OUTPUT
@ErickWendel
ErickWendel / uv_read_file.c
Created January 17, 2023 22:08 — forked from inlife/uv_read_file.c
Sample for reading a file asynchronously using libuv
// Sample for reading a file asynchronously using libuv
// taken from https://www.snip2code.com/Snippet/247423/Sample-for-reading-a-file-asynchronously
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <uv.h>
static uv_fs_t openReq;
static uv_fs_t readReq;
// I know it's not complete. It was a TDD test I made a few years ago
//index.js
const single = {
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
// @erickwendel_
import { Readable } from 'node:stream'
import { pipeline } from 'node:stream/promises'
const take = (limit) => async function* (source) {
let count = 0;
for await (const item of source) {
if (count++ >= limit) break
yield item
}
// not iterable
{
const myItem = {
a: 1,
b: 2
}
// const r = [...myItem] // TypeError: myItem is not iterable
}
// now object is iterable
const fs = require('fs');
const {
spawn
} = require('child_process')
const soxStream = require('sox-stream')
const songPath = './audio/songs/Modern Attempt - TrackTribe.mp3'
const fxPath = './audio/fx/Boo! Sound Effect (128 kbps).mp3'
const output = 'output.mp3'
const heroes = `NickName: Chapolin, Power: Hammer
Nick: Batman, Power: Money
`
const exp = /(NickName|Nick):\s(?<nickname>\w+),\sPower:\s(?<power>\w.*)/gm
const matchAll = [...heroes.matchAll(exp)].map(({
groups: {
nickname,
power
}