Skip to content

Instantly share code, notes, and snippets.

View gm50x's full-sized avatar
🐺
Rise and rise again until lambs become lions!

Getulio Magela Silva gm50x

🐺
Rise and rise again until lambs become lions!
View GitHub Profile
@gm50x
gm50x / docker-compose.yaml
Created October 25, 2023 00:28
Running docker containers (grafana, mongodb, rabbitmq) behind traefik
version: '3'
services:
traefik:
image: 'traefik:v2.10'
container_name: 'traefik'
command:
- '--api.insecure=true'
- '--providers.docker=true'
- '--providers.docker.exposedbydefault=false'
@gm50x
gm50x / permissions.js
Created April 29, 2021 12:21
Permission Grid Example (Draft)
const log = console.log
const sg = {
admin: 'admin',
authors: 'authors',
guests: 'guests'
}
const users = [
{ id: 'johndoe', email: 'johndoe@nobody.com', groups: [sg.admin, sg.authors] },
const http = require('http')
const baseApiUrl = 'http://jsonplaceholder.typicode.com'
// using error-back pattern --> or anti-pattern :)
const fetchDataWithPromise = () => {
return new Promise((resolve, reject) => {
http.get(`${baseApiUrl}/posts`, res => {
let rawData = '';
@gm50x
gm50x / promisify.js
Last active December 19, 2020 14:37
Promisified a callback function
const { promisify } = require("util");
const getCustomerInfo = (callback) => {
setTimeout(
() => callback(null, { name: "John Doe", birthdate: "1967-04-14" }),
1000
);
};
const getCustomerInfoAsync = promisify(getCustomerInfo);
/***************************************************
* Getúlio Magela Silva (gm50x)
*
* Running Instructions:
* node async-iterators {for-each|for-of|map}
*
* Reference Material (NOT MINE):
* https://zellwk.com/blog/async-await-in-loops/
***************************************************/
@gm50x
gm50x / Dockerfile
Created November 11, 2020 23:15
Node-Nestjs multiphased dockerfile
FROM node:lts-alpine3.12 AS build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM node:lts-alpine3.12 AS runtime
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
/************************************************************
* *
* ObservablesOne *
* Simples example of playing with rxjs-observables *
* *
* reqruiements: npm install rxjs *
* *
************************************************************/
// Function to create the enums
const getEnum = (obj) => {
const EEnum = {}
if (Array.isArray(obj)) {
obj.forEach((enumerator, i) => EEnum[enumerator] = i)
} else {
Object.getOwnPropertyNames(obj)
.forEach(property => {
EEnum[property] = obj[property]
const wordPlural = (word, amount) => {
word = word.toLowerCase()
if (amount === 1) {
return word
}
return pluralize(word)
}
const pluralize = word => {
/**
* Demonstrates Imprecision in C# floats running on top of .NET Core 3.1
**/
using System;
public class Program
{
public static void Main()
{
float n = 1.00f;