Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View spinscale's full-sized avatar
💻

Alexander Reelsen spinscale

💻
View GitHub Profile
@spinscale
spinscale / sample-memory-dumper.js
Created March 25, 2024 09:48
node.js cronjob to dump memory stats every second
const memoryCronJob = new CronJob("* * * * * *", async () => {
const formatMemoryUsage = (data : number) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
const memoryData = process.memoryUsage();
const memoryUsage = {
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
@spinscale
spinscale / kubens.sh
Created February 19, 2024 17:11
Switch default namespaces in k8s
function kubens() {
ns=$(kubectl get ns | awk '{ print $1 }' | grep -v '^NAME$' | fzf)
kubectl config set-context --current --namespace=$ns
}
@spinscale
spinscale / PhoneticFstTests.java
Created December 21, 2022 22:20
Lucene Suggestions using phonetic algorithms
package de.spinscale.prt;
import org.apache.lucene.analysis.custom.CustomAnalyzer;
import org.apache.lucene.analysis.phonetic.PhoneticFilterFactory;
import org.apache.lucene.search.suggest.FileDictionary;
import org.apache.lucene.search.suggest.Lookup;
import org.apache.lucene.search.suggest.analyzing.AnalyzingSuggester;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.NIOFSDirectory;
import org.junit.jupiter.api.Test;
@spinscale
spinscale / litestream-s3.yml
Last active November 21, 2023 18:43
Litestream S3 issue
exec: /app/openpixel-sqlite-tracker/bin/openpixel-sqlite-tracker
dbs:
- path: /tmp/sqlite.db
replicas:
- type: s3
region: eu-central-1
bucket: THE_BUCKET
path: /db
access-key-id: AWS_ACCESS_KEY_ID
@spinscale
spinscale / autobahn-api-to-es.cr
Last active November 26, 2023 15:14
Visualizing the unofficial autobahn API into the Elastic Stack
# autobahn-api-to-es
#
# Indexes autobahn API metadata into Elasticsearch to use it with Kibana Maps
#
# Original API description https://gist.github.com/LilithWittmann/06bd153317b635e7b622651f5cfd95ea
#
#
# MIT License
#
# Copyright (c) [2021]
@spinscale
spinscale / data.json
Created March 31, 2021 09:06
Daily Elastic Byte - Interesting field types
#############################
## unsigned long
#############################
DELETE unsigned_long_test
PUT unsigned_long_test
{
"mappings": {
"properties": {
"my_counter": {
@spinscale
spinscale / data.json
Created March 31, 2021 09:04
Daily Elastic Byte - Tale of an aggregation
# Show the scoreboard in the contributor app
DELETE scoreboard
PUT scoreboard/_bulk?refresh
{"index":{}}
{ "score" : 1, "@timestamp" : "2021-02-28", "email":"peter@example.org", "name" : "Peter Parker"}
{"index":{}}
{ "score" : 4, "@timestamp" : "2021-02-01", "email":"peter@example.org", "name" : "Peter MiddleName Parker"}
{"index":{}}
@spinscale
spinscale / examples.json
Created March 18, 2021 10:56
Elastic Bytes - rank/distance feature
###################################################
## Boosting scores based on numeric field values ##
###################################################
# Existing solution: function_score query
# Problem: Performance penalty
# Solution: Rescoring, only rescoring top-n documents
# Lucene optimization in Elasticsearch 7: Block MAX WAND
# New query: distance_feature, efficiently skips non-competitive hits
@spinscale
spinscale / runtime-fields.json
Created March 17, 2021 10:56
Elastic Bytes - Runtime fields
##################
# Runtime fields #
##################
GET /
DELETE orders
PUT orders
{
@spinscale
spinscale / calculate-vaccinations.sh
Created January 27, 2021 09:03
Download RKI data and extrapolate full first vaccination
#!/bin/bash
# retrieve URL
url="https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Daten/Impfquotenmonitoring.xlsx?__blob=publicationFile"
wget -o /dev/null $url -O out.xlsx
# convert to csv
# run 'pip3 install xlsx2csv' (or maybe pip depending on your python installation)
xlsx2csv -a out.xlsx out.csv