Skip to content

Instantly share code, notes, and snippets.

Avatar

Nicolas Grilly ngrilly

View GitHub Profile
@ngrilly
ngrilly / collision_probability.py
Last active Dec 18, 2020
Probability of collision with ULIDs on a 50 million years period
View collision_probability.py
"""
ULID probability of collision
"""
import decimal
# A ULID uses 80 bits of entropy
d = decimal.Decimal(2**80)
# Generate 1,000 ULIDs per millisecond (1,000,000 per second)
@ngrilly
ngrilly / auth.go
Created Dec 4, 2013
Sharing authentication cookies between Python and Go. This code is published in response to this discussion on golang-nuts: https://groups.google.com/forum/#!topic/golang-nuts/_nUQ1brlPBY This code is not really ready for public consumption: documentation is missing in some places, tests are missing in the Python version, code is not general eno…
View auth.go
package auth
import (
"net/http"
"net/url"
"strings"
"time"
"lib/crypto"
"lib/utils"
@ngrilly
ngrilly / bug_pg_copy_from.py
Created Feb 1, 2011
It looks like copy_from does not stop reading after an error. When the input file is short, it is okay. But when the input file is very long, it is really boring to wait for the entire file to be read just to discover there is an error on the 10th row.
View bug_pg_copy_from.py
"""
It looks like copy_from does not stop reading after an error. When the input file is short,
it is okay. But when the input file is very long, it is really boring to wait for the entire file
to be read just to discover there is an error on the 10th row.
Given the same input file, it looks like psql \copy command behaves correctly and stops
just after the incorrect row, without reading the entire file. I have checked that just by looking
at the command execution time that seems proportional to the number of processed rows...
Here is a script to reproduce this bug (just create a database "test" and run the script).