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 / certget.py
Created June 10, 2022 14:16
Download server's certificate chain with Python
#!/usr/bin/env python3
import socket
import ssl
import logging
import os
import sys
import re
import argparse
@hbobenicio
hbobenicio / main.cpp
Created April 28, 2022 15:47
Dynamic Programming - Grid Traveler
/**
* Grid Traveler solution.
*
* Try running it with row=18 col=18
*/
#include <iostream>
#include <unordered_map>
using namespace std;
@hbobenicio
hbobenicio / main.c
Last active December 16, 2022 12:57
Parsing a C-String into a Number
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
unsigned long long int cstr_to_ull(const char* str) {
char* endptr = NULL;
errno = 0;
unsigned long long int ull_value = strtoull(str, &endptr, 10);
if (errno != 0) {
@hbobenicio
hbobenicio / visitor.c
Created December 27, 2021 12:35
Visitor Pattern in C (not C++)
/**
* @file main.c
* @author Hugo Benicio <[email protected]>
* @brief Visitor Pattern implementation in C (not C++)
* @version 0.1.0
* @date 2021-12-27
*/
#include <stdio.h>
#include <stddef.h>
@hbobenicio
hbobenicio / regex-example.c
Last active March 27, 2023 01:03
Posix Regex: Using capture groups to replace missing positive lookaheads
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
#include <sys/types.h>
#include <assert.h>
static void regex_must_compile(regex_t* regex, const char* pattern, int flags);
int main() {
const char* input = " \t a b c /* foo bar\nkk";
@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
@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 / 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 / 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 / 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(),