Skip to content

Instantly share code, notes, and snippets.

View andersonbosa's full-sized avatar
🥑

Anderson Bosa andersonbosa

🥑
View GitHub Profile
import winston from 'winston'
const createWinstonLogger = () => winston.createLogger({
levels: winston.config.syslog.levels,
transports: [
new winston.transports.Console({
level: 'info',
format: winston.format.combine(
winston.format.colorize({ all: true }),
// ------------------------------- lib
import amqp from 'amqplib'
import { v4 as uuidv4 } from 'uuid'
import {
Broker,
BrokerBinding,
BrokerConfig,
@andersonbosa
andersonbosa / examples_npm_archiver.ts
Created June 4, 2024 17:45
using npmjs.com/archiver package to create zip archive with given structure
interface FileEntry {
path: string
buffer?: Buffer
contents?: FileEntry[]
}
async function zipFiles (files: FileEntry[]): Promise<Buffer> {
const archive = archiver('zip', { zlib: { level: 9 } })
const output: Buffer[] = []
import fs from 'node:fs'
import path from 'node:path'
import os from 'node:os'
import archiver from 'archiver'
interface FileNode {
name: string
content?: Buffer
children?: FileNode[]
@andersonbosa
andersonbosa / deprecated_changelogmd_generator.sh
Created May 12, 2024 16:26
deprecated changelog generator from Moshell.sh
#!/usr/bin/env bash
#
# Author: @andersonbosa
# Description: This script generates a changelog based on Git commit history.
# It identifies the last release commit, parses the commit messages, and
# categorizes them into different sections based on semantic keys. The resulting
# changelog is formatted and saved to a specified file location.
#
ABSOLUTE_SCRIPT_FILE_PATH="${BASH_SOURCE:-$0}"
interface AuthenticationService {
authenticate<I, O> (body: I): Promise<O>
}
class BasicAuthenticationService implements AuthenticationService {
async authenticate<I, O> (body: I): Promise<O> {
const r = { content: "authenticated" }
return r as O
}
@andersonbosa
andersonbosa / enum_typescript.ts
Last active May 6, 2024 20:23
enum_typescript.ts
/*
In this article, we reviewed a few ways to iterate over the keys and values of enum types
in TypeScript. First, we used the inbuilt methods of any TypeScript object, noting that
they are fairly “low-level”.
Second, we moved to a higher-level approach, with for loops. We verified that we can teach
TypeScript to preserve the typing given by enums, without relying on the string or numeric
representation.
*/
enum TrafficLight {
@andersonbosa
andersonbosa / Dockerfile
Created April 23, 2024 17:30
node_exporter service
FROM alpine:edge
WORKDIR /bin/app
RUN wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz \
&& tar -xzvf node_exporter-1.7.0.linux-amd64.tar.gz --directory . \
&& mv -v ./node_exporter-1.7.0.linux-amd64/node_exporter /bin/node_exporter \
&& chmod 777 /bin/node_exporter
@andersonbosa
andersonbosa / GithubRepositoriesTable.tsx
Created April 22, 2024 17:29
GithubRepositoriesTable.tsx
'use client'
import { HTMLAttributes, useEffect, useState } from 'react'
import { Table } from '../atoms/Table'
import { fetchGithubRepositoriesByUsername } from '@/app/lib/fetch'
import { GithubRepo } from '@/lib/types/global'
export type GithubRepo = {
name: any
@andersonbosa
andersonbosa / throttle.ts
Created April 20, 2024 16:12
typescript throttle and debounce
/**
* Allow only one call within the time limit
* @param { Function } func function to limited
* @param { Number } limit time limite in miliseconds
*/
export function throttle (func: Function, limit: number) {
let inThrottle: boolean
return function (this: any) {
const args = arguments
const context = this