Skip to content

Instantly share code, notes, and snippets.

@eribeiro
eribeiro / solr_password.py
Created November 27, 2020 17:07
Generates sha256 password with salt for use in Solr's Basic Auth setup
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import secrets
import sys
from hashlib import sha256
from base64 import b64encode, b64decode
##
## Based on the logic here: https://github.com/apache/lucene-solr/blob/master/solr/core/src/java/org/apache/solr/security/Sha256AuthenticationProvider.java
@eribeiro
eribeiro / search_relevance_evaluation_metric.py
Last active August 21, 2022 13:20
Search relevance evaluation metrics
##
## Python implementations of the search relevance evaluation metrics described at
## https://opensourceconnections.com/blog/2020/02/28/choosing-your-search-relevance-metric/
##
##
def precision(docs):
return sum(docs) / len(docs) if docs else 0
def avg_precision(docs):
@eribeiro
eribeiro / fetcher.sh
Last active January 29, 2020 22:51
Retrieves all the documents from a Solr core/collection
#!/bin/bash
## Usage:
## $ chmod +x fetcher.sh
## $fetcher.sh <output file>
SOLR_URL="http://localhost:8983/solr"
COLLECTION="teste"
ROWS=10
FL=*,score # No space around commas
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.apache.lucene.analysis.miscellaneous.DelimitedTermFrequencyTokenFilter;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.*;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TopDocs;
package com.company;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
//import org.apache.zookeeper.common.PathUtils;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
public final class PathIterator implements Iterator<String>, Iterable<String> {
public static final String SEP = "/";
@eribeiro
eribeiro / input.txt
Created November 29, 2016 19:04
input.txt
19
paralelogramos
contextualizar
companheirismo
gradativamente
especificidade
idiossincrasia
disponibilizar
corporativismo
locupletamento
@eribeiro
eribeiro / hamming.py
Created November 29, 2016 18:55
Hamming Distance
#!/usr/bin/python
def ham(x,y):
cont = 0
if len(x) == len(y):
for i in zip(x,y):
if i[0] != i[1]:
cont += 1
else:
cont = -1
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.*;
public class MapComputeTest
{
public static void main(String[] args)
{
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.51-b03 mixed mode):
"Attach Listener" #13 daemon prio=9 os_prio=31 tid=0x00007f943c05e000 nid=0x3507 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"DestroyJavaVM" #12 prio=5 os_prio=31 tid=0x00007f943a817000 nid=0x1003 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Thread-1" #11 prio=5 os_prio=31 tid=0x00007f943a816000 nid=0x5003 waiting for monitor entry [0x00007000012cc000]
java.lang.Thread.State: BLOCKED (on object monitor)