Skip to content

Instantly share code, notes, and snippets.

@inhumantsar
inhumantsar / cosine-similarity.ts
Created April 22, 2024 04:28
Cosine Similarity implemented in Typescript
//
// slammed this together after reaading an interesting from-scratch series of posts on TF-IDF + Cosine Similarity.
//
// it will be slow, if it even works. totally untested and full of misguided practices.
// might come back to this some day and make it at least functional.
//
// https://blog.christianperone.com/2011/09/machine-learning-text-feature-extraction-tf-idf-part-i/
//
class Vector extends Map<string, number> {
@inhumantsar
inhumantsar / notes.md
Last active April 12, 2024 04:22
Rootless Podman + Servarr + SELinux

SELinux == Pain

Always a shitshow.

after migrating over to CoreOS and rootless podman, the servarr stack has been throwing thousands of SELinux errors all the time. caddy generated a bunch of errors and slowed down during startup. plex, sonarr, and radarr shat the bed hard. plex in particular would lock up and take minutes to launch because of it, impacting everything else going on. this evening it took 4 tries to get it started, even after i set selinux to permissive.

no fucking more.

people say "udica". it's apparently a python script that generates SELinux configs for podman containers. let's give it a go.

@inhumantsar
inhumantsar / filesizedist.sh
Created November 30, 2022 04:47
Generate file size distribution on the commandline
# from https://superuser.com/a/1100340
find . -type f -print0 | xargs -0 ls -l | awk '{ n=int(log($5)/log(2)); if (n<10) { n=10; } size[n]++ } END { for (i in size) printf("%d %d\n", 2^i, size[i]) }' | sort -n | awk 'function human(x) { x[1]/=1024; if (x[1]>=1024) { x[2]++; human(x) } } { a[1]=$1; a[2]=0; human(a); printf("%3d%s: %6d\n", a[1],substr("kMGTEPYZ",a[2]+1,1),$2) }'
@inhumantsar
inhumantsar / ffs.sh
Created May 23, 2022 19:11
Rename a bunch of AWS Secrets Manager secrets
for secret in `aws secretsmanager list-secrets | jq -r '.SecretList[] | select(.Name | test("old-middle")) | .Name'`; do
prefix=$(echo $secret | cut -d/ -f1)
suffix=$(echo $secret | cut -d/ -f3)
content="$(aws secretsmanager get-secret-value --secret $secret | jq -r .SecretString)"
aws secretsmanager create-secret --name $prefix/new-middle/$suffix --secret-string "${content}"
done
@inhumantsar
inhumantsar / humanize.dart
Last active August 16, 2020 17:54
naturalDuration testing for humanize
void main() {
print("# core values");
var dayCounts = [
-700,
-365,
-90,
-30,
-15,
-7,
-2,
input1 = ["R990","U475","L435","D978","L801","D835","L377","D836","L157","D84","R329","D342","R931","D522","L724","U891","L508","U274","L146","U844","R686","D441","R192","U992","L781","D119","R436","D286","R787","D85","L801","U417","R619","D710","R42","U261","R296","U697","L354","D843","R613","U880","R789","D134","R636","D738","L939","D459","L338","D905","R811","D950","L44","U992","R845","U771","L563","D76","L69","U839","L57","D311","L615","D931","L437","D201","L879","D1","R978","U415","R548","D398","L560","D112","L894","D668","L708","D104","R622","D768","R901","D746","L793","D26","R357","U216","L216","D33","L653","U782","R989","U678","L7","D649","R860","D281","L988","U362","L525","U652","R620","D376","L983","U759","R828","D669","L297","U207","R68","U77","R255","U269","L661","U310","L309","D490","L55","U471","R260","D912","R691","D62","L63","D581","L289","D366","L862","D360","L485","U946","R937","D470","L792","D614","R936","D963","R611","D151","R908","D195","R615","U768","L166","D314","R640","U47","L161","U8
@inhumantsar
inhumantsar / github-create
Created January 18, 2019 19:54
github-create: create github repos from the command line, supports 2FA.
# github-create
# this function will create a new GitHub repo using credentials, including 2FA codes, supplied by the user.
# you can copy this entire file into your `~/.bashrc` or similar, or you can copy everything between the outermost
# curly braces into its own script and save that somewhere on your PATH.
# to use it, simply run `github-create` from within a local git repo.
github-create() {
HELP="""Creates a GitHub repo, sets it as the remote 'origin' for the local git repo, pushes.
@inhumantsar
inhumantsar / nb.py
Created August 29, 2017 18:40
nationbuilder python exercises
#!pip install rauth
from rauth import OAuth2Service
import json
# init work
NATION_SLUG = 'somenation'
OAUTH_ID = 'someid'
OAUTH_SECRET = 'somesecret'
REDIRECT_URI = 'http://somecallback.url'
@inhumantsar
inhumantsar / nb.py
Last active September 18, 2017 17:23
nationbuilder python exercises
#!pip install rauth
from rauth import OAuth2Service
import json
# init work
NATION_SLUG = 'somenation'
SITE_SLUG = 'somesite'
OAUTH_ID = 'someid'
OAUTH_SECRET = 'somesecret'
13:41 <alisdair> 6000 keystrokes per hour
13:41 <alisdair> that seems high
13:43 <cheeseprocedure> 100 words per minute is 6000 words per hour, yes? 6000 keystrokes should be pretty easy
13:43 <cheeseprocedure> it does seem like a bizarre metric though
13:43 <cheeseprocedure> oh, data entry
13:44 <cheeseprocedure> so probably more like punching digits into a numpad mindlessly?
14:42 <Lefty> I could probaby type 6000 keystrokes per hour using only my buttcheeks
14:42 <Lefty> in fact I'm going to apply just to attempt that
14:42 <cheeseprocedure> i look forward to your after-action report
14:42 <cheeseprocedure> also, i hope they have spare keyboards