Skip to content

Instantly share code, notes, and snippets.

View ngrilly's full-sized avatar

Nicolas Grilly ngrilly

View GitHub Profile
@ngrilly
ngrilly / bug_pg_copy_from.py
Created February 1, 2011 10:20
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.
"""
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).
@ngrilly
ngrilly / auth.go
Created December 4, 2013 09:49
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…
package auth
import (
"net/http"
"net/url"
"strings"
"time"
"lib/crypto"
"lib/utils"
@ngrilly
ngrilly / collision_probability.py
Last active December 18, 2020 12:50
Probability of collision with ULIDs on a 50 million years period
"""
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)