Skip to content

Instantly share code, notes, and snippets.

View pkoch's full-sized avatar

Paulo Koch pkoch

View GitHub Profile
// I wish I could use creates. :(
use std::collections::HashSet;
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct DecodeError(String);
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
enum Rank {
#!/bin/bash
for BRANCH in `git branch | grep -v '^*'`; do
if [ "$(git cherry origin/main $BRANCH | grep -c '^+')" -eq '0' ]; then
git branch -D $BRANCH
fi
done

https://gist.github.com/pkoch/ed52f4635a92d1028d511363efee9758

There's a few codebases I've worked on that don't give errors enough consideration, and details about them are readily swept under a carpet. They return None left and right, regardless of what came in their way. This lack of consideration and communication of the nature of the problem makes dealing with it largely impossible.

I consider that, until the end of last decade, ergonomic error handling in programming languages (and respective standard libraries) has felt mostly like an afterthought. Some of them (/me looks menacingly to PHP and JavaScript) tried to pretend they didn't have to be a thing. Things are now feeling differently, especially so when I look at Rust and Swift.

I have a clear idea of how to "do errors right". This is me expressing my opinion.

Terminology

When talking about errors, I often see incoherent terminology, so I'll establish my own. These are all leaky buckets -- I can't really offer formal definitions -- but I ne

#!/bin/bash
# pkoch: I've removed the trace funcionality, unified outputs, and only send email on non-zero result.
# Cronic v3 - cron job report wrapper
# Copyright 2007-2016 Chuck Houpt. No rights reserved, whatsoever.
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
set -eu
TMP=$(mktemp -d)
OUT=$TMP/cronic.out
-- From https://nerdyteachers.com/Explain/Platformer/#full_code
--variables
function _init()
player={
sp=1,
x=59,
y=59,
w=8,
h=8,
@pkoch
pkoch / cabula.md
Last active October 24, 2020 21:40

Listas

Criar vazia

l = []

Criar com elementos

l = [1, 'popo', [], {}]

Aceder a um index

l[0]

Contar elementos

len(l)

Adicionar um elemento

Cortesia de Álvaro Castro, da acontar.pt. Este email foi enviado para os clientes deles, e redistribuido com autorização.

Exmos. Senhores,

Devido à pandemia internacional por infecção do novo Corona Vírus, com o intuito de promover o seu combate e a protecção da saúde de todos nós, o Governo de Portugal avançou já com as seguintes medidas:

  1. Obrigações fiscais
    1. Prorrogação do prazo para entrega e pagamento do IRC de 31 de maio para 31 de julho de 2020.
    2. Prorrogação do prazo do 1º Pagamento por Conta de 31 de julho para 31 de agosto de 2020.
    3. Prorrogação do prazo do 1º Pagamento Especial por Conta de 31 de março para 30 de junho de 2020.
pub fn sounder<'a>(div: u32, msg: &'a str) -> impl Fn(u32) -> Option<&'a str>
{
move |n: u32|{
if n % div != 0 {
return None;
};
Some(msg)
}
}
commit 1b7d0c1b7ea0c44ec27df33d72306fd9655fa2bb
Author: Paulo Köch <pkoch@frctls.com>
Date: Mon May 13 10:23:18 2019 +0200
Introduce P
diff --git a/app/lib/p.rb b/app/lib/p.rb
new file mode 100644
index 0000000..4f31a50
--- /dev/null
diff --git a/app/lib/p.rb b/app/lib/p.rb
new file mode 100644
index 0000000..96e939c
--- /dev/null
+++ b/app/lib/p.rb
@@ -0,0 +1,67 @@
+module P
+ class PartialApplier < BasicObject
+ attr_reader :target
+