Skip to content

Instantly share code, notes, and snippets.

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

Halfdan Rump halfdanrump

🏠
Working from home
  • Nowcast Inc.
  • Japan
View GitHub Profile
@halfdanrump
halfdanrump / mongo_declarative_indexes.py
Last active August 2, 2019 01:40
[Declarative Indexes in MongoDB] #pymongo #mongodb
from typing import List
import pymongo
def check_indexes(
collection: pymongo.colllection.Collection, indexes: List[pymongo.IndexModel]
) -> None:
"""
Check if the indexes given in the `indexes` argument already
"""
@halfdanrump
halfdanrump / mongo_read_bulk.py
Last active July 25, 2019 04:05
[Processing data from a mongo cursor]
from datetime import datetime, timedelta
import zlib
from pymongo import MongoClient
import numpy as np
db = MongoClient("host:port")["database"]
# get all items that are no older than 30 days
query_filter = {"created_t": {"$gte": datetime.now() - timedelta(days=30)}}
# Get the data fields where the compressed numpy arrays are stored
projection = {"text_embedding": True, "image_embedding": True}
@halfdanrump
halfdanrump / colarec_taskdef.json
Created July 19, 2019 03:40
colarec_taskdef #are_aws_ecs_scheduled_tasks_worth_the_effort
[
{
"name": "colarec",
"image": "211367837384.dkr.ecr.ap-northeast-1.amazonaws.com/colarec_production:colarec-latest",
"environment": [
{
"name": "RUNTIME_ENVIRONMENT",
"value": "production"
}
],
@halfdanrump
halfdanrump / simple_logging.py
Created July 18, 2019 04:45
[simplelogging] #getting_started_on_medium
import logging
logging.warning('Watch out!') # will print a message to the console
logging.info('I told you so') # will not print anything
logging.info('New print') # will not print anything