Skip to content

Instantly share code, notes, and snippets.

View hbobenicio's full-sized avatar

Hugo Benício hbobenicio

  • Brazil
View GitHub Profile
@hbobenicio
hbobenicio / gist:1e86275064f8273827e6ac2358044986
Last active September 20, 2019 14:51
GPG / OpenPGP commands and GIT integration
# Para instalar o GnuPG2 no Ubuntu
sudo apt install gnupg2
# Para criar novas chaves
gpg2 --full-gen-key
# Para listar as chaves
gpg2 --list-secret-keys --keyid-format LONG
# Para exportar chaves
@hbobenicio
hbobenicio / .bashrc
Created September 19, 2019 14:51
Adiciona nome do branch corrente no prompt bash
# Show git branch name
# @see https://askubuntu.com/questions/730754/how-do-i-show-the-git-branch-with-colours-in-bash-prompt
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
@hbobenicio
hbobenicio / download-server-certs.sh
Created July 27, 2020 19:07
Download server certificates with openssl
#!/bin/bash
set -eu -o pipefail
HOST="foo.bar"
PORT="443"
CERTS_FILE_PATH="certs.pem"
openssl s_client \
-showcerts \
-connect "${HOST}:${PORT}" < /dev/null 2> /dev/null \
@hbobenicio
hbobenicio / notes.md
Created October 17, 2020 10:02
Tokio Notes

tokio::spawn

  • para tasks com contexto Send (i.e. type parameters da future implementam Send)

tokio::task::spawn_local

  • para tasks com contexto !Send (tasks serão "scheduladas" na mesma thread!)
  • deve-se criar um objeto task::LocalSet

tokio::task::spawn_blocking

@hbobenicio
hbobenicio / result-example.c
Created May 30, 2021 19:52
A Result type example for C
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#define OUTCOME_SUCCESS 0
typedef double DivResultOk;
// TODO For a generic error handling, you coud add a polimorphic interface here. This could help for generec error handling and error chaining.
@hbobenicio
hbobenicio / async-gen-pipeline.example.js
Last active June 3, 2021 18:55
async generator example with node.js stream pipelines
const fs = require('fs');
const path = require('path');
const { pipeline } = require('stream/promises');
async function generateFixtures() {
await Promise.all([
generateFooFixture(),
generateBarFixture(),
generateCazFixture(),
//generateDazFixture(),
@hbobenicio
hbobenicio / vtable-example.c
Last active August 5, 2021 20:43
Dynamic dispatch (vtable) example in C - Allocator
/**
* Dynamic Dispatch example in C.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
typedef struct AllocatorInterface AllocatorInterface;
typedef struct Allocator Allocator;
@hbobenicio
hbobenicio / vtable-example-value.c
Created August 5, 2021 21:04
Dynamic dispatch (vtable) example with vtable value types
/**
* Dynamic Dispatch example in C.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
typedef struct AllocatorInterface AllocatorInterface;
typedef struct Allocator Allocator;
@hbobenicio
hbobenicio / log.c
Created September 25, 2021 12:48
Simple Logging in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
// Posix
#include <errno>
#ifndef LOG_RECORD_MSG_MAX_SIZE
@hbobenicio
hbobenicio / Makefile
Created September 26, 2021 19:27
General Purpose Simple Makefile
SRC = \
$(wildcard src/snake/*.c)
OBJ = $(SRC:.c=.o)
DEP = $(OBJ:.o=.d)
BIN = snake
# MMD will generate a .d file for each .c module containing its Makefile rules (including dependencies)
# These .d files are used with the `-include` bellow
CFLAGS = -Wall -Wextra -pedantic -std=c17 -MMD -I ./src/
LDFLAGS = -Wall -Wextra -pedantic -std=c17