Skip to content

Instantly share code, notes, and snippets.

View eug's full-sized avatar
🎲
Roll the data!

Eugênio Cabral eug

🎲
Roll the data!
View GitHub Profile

Preface

Peter Naur, widely known as one of the authors of the programming language syntax notation "Backus-Naur Form" (BNF), wrote "Programming as Building" in 1985. It was reprinted in his collection of works, Computing: A Human Activity (Naur 1992).

This article is, to my mind, the most accurate account of what goes on in designing and a program. I refer to it regularly when discussing much documentation to create, to pass along tacit knowledge; and the value of the XP's metaphor-setting exercise. It also provides a way to examine a methodology's economic structure.

In the article, which follows, note that the quality of the designing programmer's work is related to the quality of the match between his theory of the problem and his theory of the solution. Note that the quality of a later programmer's work is related to the match between his theories and the previous programmer's theories.

Naur's ideas, the designer's job is not to pass along "the design" but to pass along "the theories" driving the

@eug
eug / fastmcp-fastapi.py
Last active April 16, 2025 01:32
FastMCP+ FastAPI Integration
from fastapi import FastAPI
from starlette.routing import Mount, Route
from mcp.server import FastMCP
from mcp.server.sse import SseServerTransport
mcp = FastMCP("MCP")
sse = SseServerTransport("/messages/")
async def handle_sse(request):
@eug
eug / function_call.py
Last active October 23, 2023 00:29
OpenAI Function Call Syntax Sugar
import json
import functools
class Property:
def __init__(self, name, descr_or_enum, required=False):
self.name = name
self.descr_or_enum = descr_or_enum
self.required = required
def to_dict(self):
"""
Schedule Work Breakdown Structure Uncertainty with Monte Carlo Simulations
"""
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def simulate(wbs, n=100000, proba=0.9):
""" Simulate the possible completion time of a WBS project.
Parameters
@eug
eug / pdf.sh
Created January 13, 2020 15:51
PDF file manipulation via CLI
sudo apt-get install pdftk poppler-utils texlive-extra-utils
# Merge
pdfunite in-1.pdf in-2.pdf in-n.pdf out-merged.pdf
# Rotate
# 1-endnorth
@eug
eug / mat2csv.py
Last active April 4, 2022 12:42
Convert .mat to .csv file
import numpy as np
import pandas as pd
from scipy.io import loadmat
def mat2csv(file_mat, index=False):
mat = loadmat(file_mat, squeeze_me=True)
for colname in mat.keys():
# ignore private column names
if colname.startswith("__"):
@eug
eug / Morton.cpp
Created May 22, 2018 01:42
Converts (interleave) a vector of integer (bitset) coordinates to a Morton code (represented as a bitset).
#include <vector>
#include <boost/dynamic_bitset.hpp>
namespace morton {
/**
Interleaves a vector of bitsets into a unique bitset.
@param axes the vector of axis.
@return a interleaved bitset.
*/
@eug
eug / shp_to_df.py
Created September 11, 2017 01:24
Convert a ESRI Shapefile to Pandas DataFrame
# -*- coding: utf-8 -*-
import pandas as pd
from shapefile import Reader as read_shp
def shp_to_df(shp_filepath):
data = {}
shp = read_shp(shp_filepath)
fields = shp.fields[1:] # Skip 'DeletionFlag'
records = shp.records()
@eug
eug / arithmetic_features.py
Created November 17, 2016 19:58
Generate a new feature matrix consisting of all arithmetic combinations of the features.
def arithmetic_features(X, operations=['+', '-', '/', '*'], commutative=False, inplace=False):
df = X
if not inplace:
df = X.copy()
from itertools import combinations
for x, y in combinations(df.columns, 2):
if '+' in operations:
df['%s+%s' % (x, y)] = df[x] + df[y]
@eug
eug / logging.sh
Last active November 17, 2016 19:59
Simple log functions for shell scripts
# Functions
__err() { echo -e "\033[31mError:\033[0m $1"; exit; }
__warn(){ echo -e "\033[33mWarn :\033[0m $1"; }
__info(){ echo -e "\033[34mInfo :\033[0m $1"; }
# Use
__err "You must be root."
__warn "Missing temp file"
__info "Copying 'x' file"