Skip to content

Instantly share code, notes, and snippets.

View epignatelli's full-sized avatar
🍀

Eduardo Pignatelli epignatelli

🍀
View GitHub Profile
"""Utilities for working with a tiny in-memory gradebook.
This module defines a small `Gradebook` class that stores scores for named
students and provides summary statistics such as averages.
Examples:
>>> gb = Gradebook()
>>> gb.add_score("alice", 18.0)
>>> gb.add_score("alice", 12.0)
>>> gb.average("alice")
@epignatelli
epignatelli / type_hinting.py
Created February 5, 2026 14:36
type_hinting.py
def group_average(scores):
"""Compute the average score for each group.
Args:
scores: Records like {"group": str, "score": number}. Records with missing
keys or invalid scores are ignored.
Returns:
Mapping from group name to average score.
"""
import datetime as dt
def f(x):
"""Sums purchase amounts for UK entries.
Args:
purchases: List of dicts with keys "country" and "amount".
Returns:
Total amount for purchases where country == "UK".
@epignatelli
epignatelli / bug.py
Created October 9, 2025 16:57
Coding interview
import os
import random
from dataclasses import dataclass
from typing import Dict, Any, List, Tuple
import logging
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
@epignatelli
epignatelli / insert_copyright.sh
Created January 27, 2023 11:33
Add copyright header to all python files in all directories and sub-directories
@epignatelli
epignatelli / code_interview_utils.py
Last active November 2, 2022 16:26
Useful coding interview utility functions
import decimal
import math
from typing import List
def is_prime(n: int) -> bool:
if n == 0:
return False
if n == 1:
return False
# activate shell
source $HOME/anaconda3/etc/profile.d/conda.sh
./anaconda3/bin/conda init
# download privacy notebook
git clone https://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@github.com/astanziola/privacy-exercise
conda env create -f privacy-exercise/env/environment.yml
# download computer vision notebook
git clone https://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@github.com/epignatelli/scalable-recognition-with-a-vocabulary-tree

A computer program can be seen simultaneously as a set of computer instructions or as concrete poetry formed by the indentations in the text of the program. Nicholas Negroponte, Being Digital, 1995.

Here lies a lake of data that will never be found.
In a variable called start is an int that will never be parsed.
In a variable called stop is a string that will never be trimmed.
In a variable called step is a string that will never be concatenated.
Here lies a lake of data that will never be found.
109 111 110 103 111 100 98 43 115 114 118 58 47 47 112 108 97 121 101 114 58 111 109 65 115 105 108 117 120 99 65 75 55 105 77 104 70 64 99 108 117 115 116 101 114 48 46 48 114 121 117 119 46 109 111 110 103 111 100 98 46 110 101 116

@epignatelli
epignatelli / box_upload_with_refresh.py
Last active August 25, 2021 07:45
Script to upload to box with token refresh by default
import os
from boxsdk import Client, OAuth2
from tqdm import tqdm
import keyring
CLIENT_ID = os.environ["BOX_CLIENT_ID"]
CLIENT_SECRET = os.environ["BOX_CLIENT_SECRET"]
@epignatelli
epignatelli / icon-gmail.html
Last active December 28, 2024 17:27
Fontawesome icon for Gmail
// gmail.svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 24" width="64" height="64"><path d="M29.986 27.715H2.008C.915 27.715 0 26.85 0 25.733V6.376A2.01 2.01 0 0 1 2.008 4.37h27.978c1.093 0 2.008.9 2.008 2.008v19.33c-.025 1.144-.915 2.008-2.008 2.008z" fill="#f2f2f2"/><path d="M4 27.715l11.97-8.76.076-.508L3.7 9.578l-.025 17.705z" opacity=".1" fill="#221f1f"/><g fill="#d44c3d"><path d="M2.008 27.715C.9 27.715 0 26.85 0 25.733V6.35c0-1.118.9-1.32 2.008-1.32s2.008.23 2.008 1.32v21.364z"/><path d="M2.008 5.334c1.423 0 1.703.432 1.703 1.016v21.084H2.008c-.94 0-1.703-.762-1.703-1.703V6.35c-.025-.6.28-1.016 1.703-1.016zm0-.28C.9 5.055 0 5.283 0 6.35v19.356a1.98 1.98 0 0 0 2.008 2.008h2.008V6.35C4 5.258 3.126 5.055 2.008 5.055zm27.978.28c1.296 0 1.703.254 1.703.966v19.458c0 .94-.762 1.703-1.703 1.703h-1.703V6.3c-.025-.737.407-.966 1.703-.966zm0-.28c-1.118 0-2.008.152-2.008 1.245v21.44h2.008c1.118 0 2.008-.9 2.008-2.008V6.274c-.025-1.093-.915-1.22-2.008-1.22z"/><path d="M29.986 27.715h-2.008V6.3c0-1.118