Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
ivan3bx / example.sh
Created July 14, 2024 20:30
Ping visualuzation with asciigraph + ripgrep
# Adapted from
# https://github.com/guptarohit/asciigraph
ping -i.5 google.com \
| rg "time=(.*?) " -r '$1' -o --line-buffered \
| asciigraph -r -h 10 -w 40 -c "realtime plot data (google ping in ms) from stdin"
@ivan3bx
ivan3bx / center_image.md
Created March 24, 2024 03:13
Testing center image in GFM.

Align center:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

@ivan3bx
ivan3bx / main.go
Last active March 20, 2024 19:57
K-Means clustering & calculating some stats for nutrition data
package main
import (
"fmt"
"math"
"github.com/montanaflynn/stats"
"github.com/muesli/clusters"
"github.com/muesli/kmeans"
"gonum.org/v1/gonum/stat"
@ivan3bx
ivan3bx / gaussian_transform.go
Created March 17, 2024 17:08
Applying Gaussian transform to generate weights favoring a specific value/range.
package main
import (
"fmt"
"math"
)
func gaussianTransform(w float64, target float64, sigma float64) float64 {
return 1 - math.Exp(-(w-target)*(w-target)/(2*sigma*sigma))
}
@ivan3bx
ivan3bx / prediction_interval.go
Created March 7, 2024 17:01
sample code for calculating a prediction interval across data set
package main
func predictionInterval() {
// Given values
values := []float64{
21.500000,
23.250000,
22.000000,
23.700000,
26.000000,
@ivan3bx
ivan3bx / histogram_bins.go
Created March 7, 2024 17:00
exploring various ways of determining optimal # bins across a distribution
package main
import (
"fmt"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/stat"
"gonum.org/v1/gonum/stat/distuv"
"slices"
"math"
@ivan3bx
ivan3bx / generate_previews.rb
Created February 9, 2024 17:33
Ruby script to generate screenshots for a series of URLs crawled from a sitemap.xml
require "selenium-webdriver"
require "nokogiri"
require "net/http"
BASE_URL = "http://localhost:1313"
#
# This expects several things to be true:
#
# 1. Local hugo instance running at localhosts:1313
@ivan3bx
ivan3bx / Dockerfile-hugo
Last active February 9, 2024 00:16
Simple script using Puppet to generate image previews from article links on a Hugo blog
FROM ghcr.io/peaceiris/hugo:v0.122.0-mod
RUN apt-get update && apt-get install -y \
git bash net-tools \
&& rm -rf /var/lib/apt/lists/*
# Set the working directory
RUN mkdir -p /var/www
WORKDIR /var/www
@ivan3bx
ivan3bx / encrypted_file.go
Last active October 11, 2022 20:20
Reading Rails 7x encrypted credentials from Go
package config
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"errors"
@ivan3bx
ivan3bx / example.gnuplot
Created April 1, 2021 17:11
Plotting response time from Apache Bench..
# define output file as variable (with default)
if (!exists("outfile")) outfile='output.png'
# define input file as variable (with default)
if (!exists("infile")) infile='values.tsv'
# set output format & size
set terminal png size 1024,768 crop
# set output filename (see 'outfile' variable)