Skip to content

Instantly share code, notes, and snippets.

View aplz's full-sized avatar
🍉

Anja Pilz aplz

🍉
View GitHub Profile
@aplz
aplz / draw_text_with_background_opencv.py
Last active September 3, 2023 22:56
draw text with background // opencv
import cv2 # opencv
import numpy as np
font_scale = 1.5
font = cv2.FONT_HERSHEY_PLAIN
# set the rectangle background to white
rectangle_bgr = (255, 255, 255)
# make a black image
img = np.zeros((500, 500))
@aplz
aplz / fasttext_cv.py
Created September 5, 2018 16:15
sklearn cross-validation for fasttext
import argparse
import os
import fasttext
from sklearn.base import BaseEstimator
from sklearn.metrics import f1_score
from sklearn.model_selection import cross_val_score, StratifiedKFold
def read_data(data_dir):
@aplz
aplz / test_parameterized_exception.py
Last active August 5, 2021 09:48
assert that some input results in an exception being raised
import pytest
from typing import List
def method_under_test(values: List[int]) -> int:
"""dummy method"""
if 0 in values:
raise(ValueError("Zeros are not supported"))
return sum(values)
@pytest.mark.parametrize(
@aplz
aplz / numpy_vector_to_dlib_sparse_vector.py
Last active November 26, 2020 08:21
Create a sparse vector for dlib from a numpy array
"""How to create a sparse vector for dlib from a numpy array.
dlib: http://dlib.net/
"""
import dlib
import numpy
vector = [0,2,0]
sv = dlib.sparse_vector()
for i in numpy.nonzero(vector)[0]:
@aplz
aplz / analyze_ngram.js
Created July 10, 2020 12:04
elasticsearch analyze API with customized ngram analyzer
GET _analyze
{
"text": "Quick fox",
"tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 4,
"token_chars": [
"letter",
"digit"
tui,label
T001,Organism
T002,Plant
T004,Fungus
T005,Virus
T007,Bacterium
T008,Animal
T010,Vertebrate
T011,Amphibian
T012,Bird
@aplz
aplz / es_german_analyzer.py
Last active October 16, 2019 09:17
elasticsearch-py german analyzer / tokenizer
es = Elasticsearch()
tokens = es.indices.analyze(
body={"analyzer": "german",
"text": "Die junge Informatikerin Katie Bouman machte die "
"historische Aufnahme eines schwarzen Lochs "
"möglich."})['tokens']
for token in tokens:
print(token)
@aplz
aplz / scroll.py
Created October 16, 2019 09:16 — forked from hmldd/scroll.py
Example of Elasticsearch scrolling using Python client
# coding:utf-8
from elasticsearch import Elasticsearch
import json
# Define config
host = "127.0.0.1"
port = 9200
timeout = 1000
index = "index"
@aplz
aplz / disable_spell_checker.txt
Last active April 17, 2019 08:45
locally disable spell checking in pycharm and IDEA
place the line below above the offensive code part
# noinspection SpellCheckingInspection
for IDEA, the analogon is
@SuppressWarnings("SpellCheckingInspection")
@aplz
aplz / copy_cron_jobs
Last active March 28, 2019 10:47
copy a cronjob config from one server to another
# copy your cron jobs
crontab -l > cron.txt
# copy the exported config to otherHost
scp cron.txt otherHost:/your_directory
# login to otherHost
ssh otherHost
# set the cronjobs to your old config
crontab cron.txt