Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am valentinmouret on github.
  • I am valentinmouret (https://keybase.io/valentinmouret) on keybase.
  • I have a public key ASA9ccYAo84bLPqRzX5ouW4jonia1dyOeqnfXpW5wW07fgo

To claim this, I am signing this object:

from typing import Any, Iterable, List
def partition(coll: Iterable[Any], size: int, use_padding=False) -> Iterable[Any]:
"""Lazily partition the iterable by making batches of size `size`.
Arguments:
* coll: iterable to partition
* size: size of the desired partitions
* use_padding: whether to use padding for the last batch in case it’s smaller
@ValentinMouret
ValentinMouret / create_firestore_collection.sql
Last active June 6, 2022 16:27
Simple table to store Firestore documents
create table firestore.collection (
 id text primary key,
 document jsonb not null
);
insert into firestore.collection
  (id, document)
values ('9782738154262',
'
{
"title": "le plan de transformation de l''économie française",
"author": "The Shift Project"
}
');
select document
from firestore.collection
where id = '9782738154262';
select document->>'title' as title,
  id as isbn
  from firestore.collection
 where document->>'author' = 'The Shift Project';
create index firestore_collection_document_idx
  on firestore.collection
  using gin(document);
create table users (
name text primary key,
age int not null,
is_adult boolean generated always as (age >= 18) stored
);
insert into users
(name, age)
values ('Zola', 54),
('Rimbaud', 8);
alter table firestore.collection
add column author text generated always as (document->>'author') stored;
create index firestore_collection_author_idx
on firestore.collection (author);
create table user (
 id text primary key,
 email text not null
);