Skip to content

Instantly share code, notes, and snippets.

View justahero's full-sized avatar

Sebastian Ziebell justahero

View GitHub Profile
@justahero
justahero / heart_rate_zones.rs
Created September 9, 2024 12:52
Calculate Heart Rate Zones
/// Prints the heart rate zones assuming a 5 zones distribution with
/// simple ranges. Adjust to your liking.
fn print_zones(resting_heart_rate: u16, max_heart_rate: u16) {
let zones = [(50, 60), (60, 70), (70, 80), (80, 90), (90, 100)];
let heart_rate_reserve = max_heart_rate - resting_heart_rate;
for (index, (lower, upper)) in zones.iter().enumerate() {
let lower = resting_heart_rate + heart_rate_reserve * lower / 100;
let upper = resting_heart_rate + heart_rate_reserve * upper / 100;
@justahero
justahero / libaxum_core.cargo-sbom.json
Created April 6, 2024 14:28
Cargo SBOM output examples
{
"format_version": 1,
"package_id": "path+file:///Users/sziebell/dev/temp/axum/axum-core#0.4.3",
"name": "axum-core",
"version": "0.4.3",
"source": "/Users/sziebell/dev/temp/axum/axum-core",
"target": {
"kind": [
"lib"
],
@justahero
justahero / elasticsearch-docker.md
Last active November 17, 2020 13:59
Elasticsearch Docker setup for local development

Setup

To set up a minimal environment with Elasticsearch and Docker

Docker

To run Elasticsearch the following docker command uses the official Docker image. Open your terminal and run:

@justahero
justahero / wt_settings.json
Last active April 26, 2020 10:20
Windows Terminal Profiles, for a similar experience as on OSX / Linux
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"profiles":
@justahero
justahero / es_analyzer_stack_trace.md
Last active January 15, 2019 15:05
Elasticsearch analyzer for stack traces.

Example stack trace in Ruby

divide_by_zero.rb:2:in `/': divided by 0 (ZeroDivisionError)
        from divide_by_zero.rb:2:in `divide'
        from divide_by_zero.rb:5:in `<main>'

The following analyzer is a first draft of how to split / analyze the stack trace. The user should be able to search for file name, line number, exception. Only the first two lines of the stack trace are analyzed.

@justahero
justahero / elasticsearch_percolator_example.md
Last active December 5, 2018 10:42
Elasticsearch Percolator Query example

Percolator Query

This setup shows how to use a percolator query, for more details see Percolator Query documentation.

The following setup was tested with Elasticsearch 6.5.

Create a new index with a given mapping, the document only accepts a message field

curl -X PUT 'http://localhost:9200/percolator' -H 'Content-Type: application/json' -d '{
@justahero
justahero / to_proc.rb
Last active December 9, 2017 12:18
Example on how to use to_proc with Ruby classes
# class to test behaviour of Proc and to_proc
class ProcTest
def initialize(text='')
@text = text
end
def say
puts "say #{text}"
end
@justahero
justahero / consul_api.md
Last active October 23, 2017 20:11
Cheatsheet Consul API

Consul API

The following commands assume a running consul instance on localhost:8500.

Agent + Health

List all checks from local node

@justahero
justahero / default.yaml
Created September 8, 2017 10:02
Modified beaker box configuration to be able to run Elasticsearch successfully
HOSTS:
centos-7-x64-master:
roles:
- master
- agent
platform: el-7-x86_64
hypervisor: vagrant
box: puppetlabs/centos-7.2-64-nocm
vagrant_memsize: 2048 # increase memory or OutOfMemoryError will occur
vagrant_cpus: 2 # to speed things up a little
@justahero
justahero / Vagrantfile
Last active March 5, 2018 16:39 — forked from ampedandwired/Vagrantfile
Configure VM / docker with company proxy CNTLM
# put the following content into ~/.vagrant/Vagrantfile
# install plugin vagrant-proxyconf: vagrant plugin install vagrant-proxyconf
VAGRANTFILE_API_VERSION = "2"
def get_proxy_url
# Doesn't support different proxies for different protocols at present
host_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || ENV['https_proxy'] || ENV["HTTPS_PROXY"]
if host_proxy
uri = URI(host_proxy)