Skip to content

Instantly share code, notes, and snippets.

View andersonbosa's full-sized avatar
🥑

Anderson Bosa andersonbosa

🥑
View GitHub Profile
@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
@andersonbosa
andersonbosa / 1.sh
Last active April 18, 2024 17:11
Scaffold a typescript project quickly
#!/bin/bash
# CREATE INITIAL FILES
cat > package.json <<EOF
{
"name": "@typescript/scaffold",
"version": "1.0.0",
"author": "Anderson Bosa",
"license": "CC0-1.0",
"keywords": ["typescript"],
@andersonbosa
andersonbosa / Makefile.docker.md
Last active April 12, 2024 14:42
Generic Makefile to help you boost your productivity with Docker

Variables

DOCKER_IMAGE_NAME := my-docker-image DOCKER_CONTAINER_NAME := my-container DOCKER_BUILD_DIR := . DOCKERFILE := Dockerfile DOCKER_RUN_COMMAND := /bin/bash

Commands

build:

@andersonbosa
andersonbosa / npm_automated_dependencies_update.sh
Last active April 11, 2024 21:31
NPM: How to Keep Dependencies Up-To-Date
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# This command will check every installed dependency and compare the current
# version with the latest version in the npm registry. It is printed out into
# a table outlining available versions.
npm outdated
@andersonbosa
andersonbosa / add_new_document.sh
Last active April 11, 2024 18:09
Add new item from a defined template. Useful for initing new documents like RFC's from a template.
#!/bin/bash
# Author: https://github.com/andersonbosa
# Source: https://gist.githubusercontent.com/andersonbosa/2596ce7856f08299e0e065ccfe878bb4/raw/fd823a48c736288ab9d0b7da3cab05e2f60ff2a4/add_new_document.sh
set -e
#######################################
# Function to convert a string to title case
# Arguments:
# $1: String to be converted to title case
@andersonbosa
andersonbosa / replace_keyword.sh
Last active April 11, 2024 18:01
Bash function to replace a keyword with a provided value in a text file
#!/bin/bash
# Author: https://github.com/andersonbosa
# Source: https://gist.githubusercontent.com/andersonbosa/9966c985fb5baf250271447746a714a3/raw/31cba94a8db1acbeb3636e272e1345745c72891e/replace_keyword.sh
#
# Example usage:
# replace_keyword "example.txt" "{{title_template}}" "New Title"
#######################################
# Function to replace a keyword with a provided value in a text file
@andersonbosa
andersonbosa / coderbyte__array_jumping.py
Last active April 2, 2024 14:00
coderbyte__array_jumping.py
def ArrayJumping(arr):
# Inicialização de um dicionário para armazenar as informações de salto para cada índice na lista
hashtable = {}
# Obter o comprimento da lista
arr_len = len(arr)
# Preencher o dicionário com informações de salto para cada índice na lista
for i in range(arr_len):
hashtable[i] = (left(arr_len, i, arr[i]), right(arr_len, i, arr[i]))
'''
# 5 seconds
- return the smallest number you can get by reduction
# CONSTRAINS
# RULES
1. The method is: Only the letters a, b, and c will be given