Skip to content

Instantly share code, notes, and snippets.

View ErickWendel's full-sized avatar

Erick Wendel ErickWendel

View GitHub Profile
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
}
@ErickWendel
ErickWendel / concat-streams.mjs
Last active May 19, 2023 18:04
Example of how to consume multiple Web APIs in parallel via Node.js Streams
// npm i axios stream-concat
import { pipeline } from 'stream/promises'
import StreamConcat from 'stream-concat'
import axios from 'axios'
const API_01 = 'http://localhost:3000'
const API_02 = 'http://localhost:4000'
const streams = (await Promise.all([
axios({
class Context {
static printSomething() { console.log('context working',) }
static initializeTerminalWithClosure() { return () => this.printSomething() }
static initializeTerminal() { this.printSomething() }
}
setTimeout(Context.initializeTerminal)
// erro pois "this" é do contexto de setTimeout
setTimeout(Context.initializeTerminal.bind(Context))
// com bind você fala o que é para ter no "this" da função