Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
RafaelGSS / main.c
Created September 25, 2017 23:16
example-stack-simple
#include <stdio.h>
typedef struct stack {
int size;
char value[64];
} Stack;
void push(struct stack *s, char c){
s->value[s->size] = c;
@RafaelGSS
RafaelGSS / listEx.cpp
Created October 11, 2017 16:47
Simple example List
struct LNode {
int data;
LNode* next;
LNode(int n){data = n; next = NULL;}
void add_to_end(int n) {
if (next)
next->add_to_end(n);
else
next = new LNode(n);
@RafaelGSS
RafaelGSS / bubble.py
Created April 16, 2018 01:05
Bubble sort
def bubble(vector):
fim = len(vector)
for i in (fim-1, 0, -1):
for j in (0, i):
if vector[j] > vector[j+1]:
vector[j], vector[j+1] = vector[j+1], vector[j]
# O Algoritmo bubble sort tem o intuito de ordenar os itens do pesado para o mais leve, por isso o for comeca iterando o vetor todo
# e depois ele itera o vetor-1, porque o vector+1 ja esta o item mais pesado
@RafaelGSS
RafaelGSS / ShoppingCart.vue
Last active February 10, 2019 14:26
ExampleShopppingCart
<template>
<div class="header-cart middle-same">
<button class="icon-cart">
<i class="pe-7s-shopbag cart-bag"></i>
<span
class="count-amount"
id="count-amount"
>{{ sumCart | toReal }}</span>
<i class="ion-chevron-down cart-down"></i>
<span class="count-style">{{ itemsCart.length }}</span>
@RafaelGSS
RafaelGSS / schema.gql
Created May 6, 2019 17:49
Example GraphQL types pagination.
type Category implements IRecord {
id: ID!
products: [Product]!
category_name: String!
created_at: String!
updated_at: String
}
type CategoriesResource implements IResource {
pagination: Pagination!
@RafaelGSS
RafaelGSS / plugin1.js
Last active July 26, 2019 01:12
Example Fastify Plugin
module.exports = (fastify, opts, next) => {
console.log(fastify.configuration) // { db: 'alguma-database', port: 800 }
fastify.decorate('configurationPlugin1', {
name: 'plugin1'
})
console.log(fastify.configurationPlugin1) // { name: 'plugin1' }
next() // Nunca se esqueça de liberar esse handler com `next`.
@RafaelGSS
RafaelGSS / index.js
Last active July 25, 2019 16:48
Example of Fastify+Swagger
const fastify = require('fastify')()
// Registrando o Swagger
fastify.register(require('fastify-swagger'), {
routePrefix: '/docs', // Rota para acessar a UI do Swagger
exposeRoute: true,
swagger: {
host: 'localhost:3000',
schemes: ['http'],
consumes: ['application/json'],
@RafaelGSS
RafaelGSS / index.js
Created July 26, 2019 01:13
Index Example Fastify Plugin
const fastify = require('fastify')()
fastify.decorate('configuration', {
db: 'alguma-database',
port: 800
})
//Plugin1
fastify.register(require('./plugin1.js'))
//Plugin2
fastify.register(require('./plugin2.js'))
@RafaelGSS
RafaelGSS / consumer.js
Last active September 1, 2019 23:54
Communication between microservices - RabbitMQ - CW Pattern - consumer
const amqp = require('amqplib')
async function createConnection (uri = 'guest:guest@localhost:5672') {
const connection = await amqp.connect('amqp://' + uri)
return connection
}
createConnection()
.then(conn => conn.createChannel())
.then(ch => {
@RafaelGSS
RafaelGSS / producer.js
Created September 2, 2019 00:29
Communication between microservices - RabbitMQ - Producer
const amqp = require('amqplib')
async function createConnection (uri = 'guest:guest@localhost:5672') {
const connection = await amqp.connect('amqp://' + uri)
return connection
}
createConnection()
.then(conn => conn.createChannel())
.then(ch => {