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 / 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 / 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 / volume.lua
Created April 16, 2017 18:19
Hammerspoon: Configure volume via keyboard shortcuts for macbook pro (touchbar, but no keys)
function changeVolume(diff)
return function()
local current = hs.audiodevice.defaultOutputDevice():volume()
local new = math.min(100, math.max(0, math.floor(current + diff)))
if new > 0 then
hs.audiodevice.defaultOutputDevice():setMuted(false)
end
hs.alert.closeAll(0.0)
hs.alert.show("Volume " .. new .. "%", {}, 0.5)
hs.audiodevice.defaultOutputDevice():setVolume(new)
@spinscale
spinscale / runtime-fields.json
Created March 17, 2021 10:56
Elastic Bytes - Runtime fields
##################
# Runtime fields #
##################
GET /
DELETE orders
PUT orders
{
@spinscale
spinscale / filebeat.yml
Created February 14, 2020 16:35
Use filebeat to read CSV data
# Data is from https://www.sciencedirect.com/science/article/pii/S2352340918315191
filebeat.inputs:
- type: stdin
setup.template.overwrite: true
setup.template.append_fields:
- name: arrival_date
type: date
@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 / 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 / ingest node example
Created January 18, 2017 11:55
ingest node example
DELETE _all
PUT _ingest/pipeline/rename_hostname
{
"processors": [
{
"rename": {
"field": "hostname",
"target_field": "host",
"ignore_missing": true