Skip to content

Instantly share code, notes, and snippets.

View hernantz's full-sized avatar
🏠
Working from home

hernantz

🏠
Working from home
View GitHub Profile
@hernantz
hernantz / convo.md
Last active June 9, 2017 13:07
Unit tests vs Meaningful tests

That dev told me:

This too is to abstract the test from things i don't want to really test, that sould be tested in the calendar's model test. Abstracting from others components and models behavior is especially useful when you don't know ALL the behavior of everything in the app, and because that behavior shouldn't be tested in this model, so you save time by not having to know how that component/model exactly works and by not setting a lot of enviroment variables.

And I answered:

You are right, if writing unit tests is what you want.

I'm asking, please, do not, go further, and write tests that assume less.

@hernantz
hernantz / batalla naval
Created January 3, 2019 04:23
Estrategia muy simple de la batalla naval
Armar listados
--------------
1) Tener un listado de puntos para cada barco donde hay que disparar
2) Para obtener esos puntos dividir la grilla en grillas menores de n x n, donde n es el tamanio del barco
3) Para cada grilla, agregar los puntos de la diagonal (superior izquierdo a inferior derecho) a los listados de puntos a disparar para cada barco de ese tamanio
4) Crear un listado vacio para almacenar los puntos a donde no disparar (lleno de aciertos y fallos)
5) Ir a modo busqueda
Modo busqueda
@hernantz
hernantz / logging_extra_formatter.py
Created March 26, 2019 12:55
Logs all extra args
import logging
class ExtraFormatter(logging.Formatter):
defs = set(logging.LogRecord(None, None, None, None, None, None, None).__dict__.keys())
def format(self, record):
extra = set(record.__dict__.keys()) - self.defs
if extra:
# Override message with extra info
@hernantz
hernantz / if.py
Created November 24, 2019 22:33
Real world ifs and elses
def extract_timestamp(self):
record = self.get_parsed_record()
timestamp = record.get('timestamp')
if timestamp is None:
return None
if isinstance(timestamp, datetime):
return timestamp
return dateutil.parser.parse(record['timestamp'])