Skip to content

Instantly share code, notes, and snippets.

View aplz's full-sized avatar
🍉

Anja Pilz aplz

🍉
View GitHub Profile
GET index/_search
{
"query": {"match_all": {}},
"sort": [
{
"path_to_field.time": {
"order": "desc",
"nested_path": "path_to_field"
}
}
@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):
def rotateWithShapeFit(image, rotations=None):
"""
Rotates the given image by 90, 180 or 270 degrees, keeping the original image shape.
The original shape is kept by adding black borders both at the top and bottom or the left and the right of the
rotated image.
Args:
image: the image to rotate.
rotations: the number of rotations by 90 degrees. 1 will rotate the image by 90°, 2 by 180° and 3 by 270°.
@aplz
aplz / filtering_by_number_of_items_in_field.java
Created July 5, 2018 09:44
elasticsearch: script query to filter by number of items in field
// create the script query
ScriptQueryBuilder scriptQuery = QueryBuilders.scriptQuery(new Script("params._source.your_field.size() > 1"));
// add the query in a boolean term to enforce the filter
client.prepareSearch(indices).setQuery(QueryBuilders.boolQuery().must(scriptQuery)).get();
// the response will only contain documents whith more than one item in the field "your_field"
@aplz
aplz / crop_object_from_image.py
Created June 29, 2018 14:14
Crop rectangular object from image.
# working version of https://bretahajek.com/2017/01/scanning-documents-photos-opencv/
import cv2
import numpy as np
def resize(img, height=800):
""" Resize image to given height """
ratio = height / img.shape[0]
return cv2.resize(img, (int(ratio * img.shape[1]), height))
@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 / 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
@aplz
aplz / commit_emojis.md
Last active September 26, 2018 09:45
commit emojis
  • 💄 cosmetic changes without functional changes
  • ♻️ refactoring
  • 🚀 finalizing new version / release
  • 📚 documentation
  • 🙏 experimental code (without test)
  • 🚧 work in progress
  • ✨ new feature
  • 🗑️ deleting unused code
  • 🔈 added logging
  • 🔇 reduced logging
@aplz
aplz / move_between_elastic_indices.json
Created September 13, 2017 15:17
Move document from one elasticsearch index to another
POST _reindex
{
"source": {
"index": "source_idx",
"type": "sourc_idx_type",
"query": {
"terms": {
"_id": [
"the_id"
]
List<Map<String, Object>> listOfMaps = Lists.newArrayList();
listOfMaps.add(ImmutableMap.of("a",1.0));
listOfMaps.add(ImmutableMap.of("b",1.0));
listOfMaps.add(ImmutableMap.of("b",2.0));
List<Object> allValues = listOfMaps.stream()
.flatMap(map -> map.values().stream())
.collect(Collectors.toList());
assertThat(allValues, Matchers.containsInAnyOrder(1.0,1.0,2.0));