Skip to content

Instantly share code, notes, and snippets.

@nikolaybotev
nikolaybotev / xe-rates-to-csv.js
Created March 25, 2023 03:05
Convert XE currency rates JSON to CSV
let c1 = require('./currency-rates-2.json')
console.log('Date,', c1.from, 'to', c1.to)
let c1b = c1.batchList[0]
let ts = c1b.startTime
for (let i = 1; i < c1b.rates.length; i += 1) {
let actualrate = c1b.rates[i] - c1b.rates[0]
console.log(new Date(ts).toLocaleDateString() + ', ' + actualrate)
ts += c1b.interval
@nikolaybotev
nikolaybotev / compound_interest_monthly.js
Created August 24, 2022 13:49
Compute Monthly Compound Interest Payments and Amortization
// Brute force compound interest loan payment calculator
// Inputs
let amount = 100_000 // dollars
let interest = 10 // percent per year
let term = 30 // years
// Monthly Payment
let monthly_interest = (interest / 12) / 100
let no_of_payments = term * 12
@nikolaybotev
nikolaybotev / pi-bootstrap
Last active January 29, 2022 21:43
Raspberry Pi Headless Bootstrap Script
#!/bin/bash
# pi-bootstrap
#
# Setup an Ubuntu Raspberry Pi image for headless boot.
#
# Copyright Nikolay Botev, MIT License
#
# Default settings
@nikolaybotev
nikolaybotev / robinhood-download-crypto-.js
Created December 11, 2021 14:15
Robinhood Crypto Transaction Download Script
(function () {
function toCtDate(event) {
const p2 = s => s.toString().length == 1 ? "0" + s : s;
return `${p2(event.getUTCMonth()+1)}/${p2(event.getUTCDate())}/${event.getUTCFullYear()} ${p2(event.getUTCHours())}:${p2(event.getUTCMinutes())}:${p2(event.getUTCSeconds())}`;
}
const coinMap = {
"Dogecoin": "DOGE",
"Ethereum": "ETH"
}
@nikolaybotev
nikolaybotev / screen-cheatsheet.md
Last active September 29, 2021 17:54
screen Cheatsheet

Screen Cheatsheet

Essentials

Technically all the commands in this section apply to screen sessions. For brevity, we refer to screen sessions as simply screens.

Open a New Screen

screen
@nikolaybotev
nikolaybotev / turn-off-led@.service
Last active November 27, 2023 19:58
systemd service to turn off Raspberry Pi LEDs on startup.
[Unit]
Description=Turn Off LED %i
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c 'echo 0 > /sys/class/leds/%i/brightness'
ExecStop=/bin/sh -c 'echo 255 > /sys/class/leds/%i/brightness'
@nikolaybotev
nikolaybotev / iptables-firewall-config.sh
Created June 11, 2021 04:41
Router Firewall Configuration (iptables)
UPSTREAM_IFACE="${1:-eth1}"
# IPv4 and IPv6
for iptables in iptables ip6tables; do
# :INPUT
# - returning traffic
sudo $iptables -A INPUT -i $UPSTREAM_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
# - ping
sudo $iptables -A INPUT -i $UPSTREAM_IFACE -p icmp -j ACCEPT
@nikolaybotev
nikolaybotev / spiritual_autolysis.js
Last active March 26, 2021 03:01
Spiritual Autolysis - by Jed McKenna
import { tired, sleep, eat, walk } from “my_body/index.js”;
import { pray } from “my_body/heart.js”;
import { wahtDoIKnow, why } from “my_body/brain.js”;
const knowledge = [];
function write() {
while (!tired()) {
const text = knowledge.shift() || wahtDoIKnow();
text.split(“ “).forEach(word => {
@nikolaybotev
nikolaybotev / sendsms
Last active May 14, 2021 03:36 — forked from artizirk/sendsms.sh
Send SMS using AT commands over the TTY of a Cellular modem. Supports Unicode international characters and emojis.
#!/bin/sh -e
# Usage: sendsms +375555555 "some text i want to send"
TELFNUMB="$1"
SMSTEXT="$2"
MODEM="${3:-/dev/ttyUSB2}"
TIMEOUT="${4:-1}"
# Text encoding
@nikolaybotev
nikolaybotev / pidiskmark.sh
Last active November 18, 2021 20:36
A CrystalDiskMark equivalent benchmark script for Raspberry Pi OS Linux (requires fio)
#!/bin/sh
crystalread() {
awk -F \; '{ printf("%32s : %8.2f MB/s [%9.1f IOPS]\n", $3, $7*1024/1e6, $8) }'
}
crystalwrite() {
awk -F \; '{ printf("%32s : %8.2f MB/s [%9.1f IOPS]\n", $3, $48*1024/1e6, $49) }'
}