Skip to content

Instantly share code, notes, and snippets.

@diasbruno
diasbruno / bucket.e
Created November 10, 2024 20:01
Simple program in Eiffel to demonstrate design by contract.
note
description : "root class of the application"
date : "$Date$"
revision : "$Revision$"
class
APPLICATION
inherit
ARGUMENTS_32
@diasbruno
diasbruno / template_pattern.c
Last active July 23, 2024 11:18
Template pattern in c.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HUMAN 0
#define DOG 1
struct animal {
int type;
char* name;
@diasbruno
diasbruno / ip_address_eth0.sh
Created April 15, 2024 12:46
Find host's IP
#!/bin/env bash
set -eu
ip -br a s eth0 | awk '{ split($3,a,"/"); print a[1]; }'
@diasbruno
diasbruno / rpmbuild-tree.sh
Created April 5, 2024 19:24
Example of RPM packaging on /usr/local/bin
.
├── BUILD
│   ├── test-0.0.1
│   │   └── test.sh
│   └── test.sh
├── BUILDROOT
├── RPMS
│   └── x86_64
│   └── test-0.0.1-1.el8.x86_64.rpm
├── SOURCES
@diasbruno
diasbruno / pipelines_de_erros.ts
Last active February 11, 2024 01:55
Pipeline de errors.
// `isAuth`, `validateBody` e `addCredit` podem term cada um um tipo de erro diferente.
// temos 2 maneiras: classificar os erros no mesmo dominio (mais comum)
// ou, precisa de um objeto de unificação (existem outras tecnicas mais exóticas).
// Modo mais comum.
class CreateAccountErrors {}
class NotAuthError extends CreateAccountErrors {}
class ValidateCreateAccountError extends CreateAccountErrors {}
class AddCreditError extends CreateAccountErrors {}
@diasbruno
diasbruno / shell.nix
Last active November 21, 2023 11:54
Fix to run Erlang/Elixir from nix on macOS ()
{ nixpkgs ? import <nixpkgs> {} }:
let
inherit (nixpkgs) pkgs;
erlang = nixpkgs.beam.interpreters.erlangR25.override {
configureFlags = ["--disable-jit"];
};
beamPackages = nixpkgs.beam.packagesWith erlang;
in pkgs.mkShell {
nativeBuildInputs = with pkgs; [erlang elixir];
}
@diasbruno
diasbruno / haskell-github-action-with-coverage.org
Last active February 18, 2023 20:54
haskell github action with coverage

haskell github action with coverage

@github:haskell/actions

enabling coverage

This requires your project to be configured with `–enable-coverage`. This way it compiles in a way to be instrumented.

@diasbruno
diasbruno / daggy_example.js
Created January 27, 2023 17:01
data types with daggy example.
const { taggedSum } = require('daggy');
const AuthenticationError = taggedSum(
'AuthenticationError',
{
AccountSuspended: [],
InformationMismatch: [],
}
);
@diasbruno
diasbruno / base_component.js
Created October 20, 2022 19:24
dependency inversion with closures
export default function BaseComponent(apicall) {
return (props): React.FC => { // <<- this is the real renderable component
const { /* ... */ } = useUser(apicall);
return /* ... */
};
}
@diasbruno
diasbruno / vdom.hs
Created July 11, 2022 21:08
micro virtual dom
module MVD where
data Kind = Div | A
deriving (Eq, Show)
data Opts = ClassName String
deriving (Eq, Show)
data HTML = HTML Kind Opts
| HText String