Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am luminoso on github.
  • I am luminoso (https://keybase.io/luminoso) on keybase.
  • I have a public key whose fingerprint is 69E8 E8A1 0F70 B513 1949 008B 2E09 50FE 5A90 AAD1

To claim this, I am signing this object:

@luminoso
luminoso / local_kafka.sh
Last active January 17, 2020 17:21
start local kafka server
### Starting Zookeeper
./bin/zookeeper-server-start.sh config/zookeeper.properties
### Starting Kafka
./bin/kafka-server-start.sh config/server.properties
#################################################
### Topic creation
./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic ipma.3days_day
@luminoso
luminoso / kafka_send_statistics.py
Last active January 21, 2020 00:17
kafka producer send stats callback ensure message delivery
stats = {
"errors": 0,
"successes": 0,
"min_offset": None,
"max_offset": None,
"errorTypes": {}
}
def errback_listener(error, **kargs):
if type(error).__name__ not in kargs["stats"]["errorTypes"]:
@luminoso
luminoso / tricks.py
Created January 17, 2020 17:20
jupyter notebook tricks
# list magics
%lsmagic
#
# print all outputs of a cell
#
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
#
@luminoso
luminoso / serialize_jsolines_gz.py
Last active March 13, 2023 09:47
jsonlines compressed serialization gz write file
# reads and writes compressed jsonlines to a file
# from bson import json_util
# writeall_jsonl_gz('filename.jsonl.gz', objects, dumps=json_util.dumps)
import gzip
# !python -m pip install jsonlines
from typing import List, Dict
import jsonlines
@luminoso
luminoso / jupyter_init.py
Last active February 28, 2020 15:59
jupyterbook init magics
# auto reload modules/files
%load_ext autoreload
%autoreload 2
# print execution times
%load_ext autotime
# interactive matplotlib outputs
%matplotlib inline
@luminoso
luminoso / mongo_connect.py
Created January 20, 2020 16:17
quick connnect mongo pymongo
from pymongo import MongoClient
# pprint library is used to make the output look more pretty
from pprint import pprint
import urllib.parse
username = urllib.parse.quote_plus('xx')
password = urllib.parse.quote_plus('yy')
client = MongoClient(f'mongodb://{username}:{password}@172.31.8.226:27017/')
@luminoso
luminoso / ijulia.jl
Created January 22, 2020 09:36
add IJulia CentOS 7.x ZMQ ABI GLIBCXX
# trick to make iJulia work on CentOS 7
# CentOS looks like to have some kind of ABI incompatibility
# ERROR: LoadError: InitError: could not load library "/home/centos/.julia/artifacts/8b67c92bc6eb60d96d3488bf4b48bd3a38f70c53/lib/libzmq.so"
# /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /home/centos/.julia/artifacts/8b67c92bc6eb60d96d3488bf4b48bd3a38f70c53/lib/libzmq.so)
]
add ZMQ@1.1.0
add iJulia
using iJulia
@luminoso
luminoso / test_pytorch_cuda.py
Created January 22, 2020 10:20
test CUDA avaialbility pytorch
# tests the avalability of cuda for pytorch
import torch
torch.cuda.current_device()
torch.cuda.device(0)
torch.cuda.device_count()
torch.cuda.get_device_name(0)
torch.cuda.is_available()
@luminoso
luminoso / logging.py
Created January 22, 2020 18:11
python logging init
import logging
# level=logging._nameToLevel[verbosity_level]
# level=logging.DEBUG
# format="%(asctime)s [%(module)-12.12s] [%(levelname)-5.5s] %(message)s",
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s [%(levelname)-5.5s] %(message)s",