Skip to content

Instantly share code, notes, and snippets.

@nileshtrivedi
nileshtrivedi / home-server.md
Last active January 10, 2024 06:30
Home Server setup: Raspberry PI on Internet via reverse SSH tunnel

Raspberry Pi on Internet via reverse SSH tunnel

HackerNews discussed this with many alternative solutions: https://news.ycombinator.com/item?id=24893615

I already have my own domain name: mydomain.com. I wanted to be able to run some webapps on my Raspberry Pi 4B running perpetually at home in headless mode (just needs 5W power and wireless internet). I wanted to be able to access these apps from public Internet. Dynamic DNS wasn't an option because my ISP blocks all incoming traffic. ngrok would work but the free plan is too restrictive.

I bought a cheap 2GB RAM, 20GB disk VM + a 25GB volume on Hetzner for about 4 EUR/month. Hetzner gave me a static IP for it. I haven't purchased a floating IP yet.

@nileshtrivedi
nileshtrivedi / Caddyfile
Created November 14, 2021 18:30
Caddy on fly.io as reverse proxy to services on Tailscale network
log stdout
errors stdout
auto_https off
http://myapp.fly.dev {
reverse_proxy 100.120.108.62:8000
}
@nileshtrivedi
nileshtrivedi / web-identity.md
Last active October 29, 2023 17:38
Light-weight Identity for the Web using Browser Sync and Push

Light-weight Identity for the Web using Browser Sync and Push

(This is just a rough idea intended to trigger a discussion. Details need to be fleshed out for a proper evaluation.)

Signing up and logging into website continues to be painful. For a while, there were attempts like the Mozilla Persona project but those were discontinued and that has led to social logins gaining prominence, with all the concerns of centralization, privacy, surveillance etc as valid as ever. In fact, more and more websites are now adopting Google's One Tap login because the convenient UX is giving them better conversions.

However, some things have changed in recent years:

  • Push notifications are now widely supported in browsers. This is relevant because one of the main reasons why websites insist on user registration is so that they can communicate with the users via email or phone when they are offline.
@nileshtrivedi
nileshtrivedi / README.md
Last active August 2, 2023 09:18
How to set up your own fediverse instance

How to set up your own fediverse instance

FYI, we offer free managed hosting to Indian organizations (media, academia, institutions and non-profit/for-profit companies).

We're sharing our approach here to make it easy for those who want to do it themselves.

What you need

  • A domain name: A typical practice is to use a subdomain. For example, if your org website is at thinktank.com, you can set up your fediverse instance at social.thinktank.com. This will allow your users to have an email address like john@thinktank.com and fediverse address as @john@social.thinktank.com. It's also possible to run the fediverse instance on your top-level domain (eg: thinktank.com). In this case, both the email address and fediverse address will be john@thinktank.com. But users visiting thinktank.com in the browser will directly land on your fediverse instance which can't be customized as much as a proper website can be.
@nileshtrivedi
nileshtrivedi / ncert.rb
Created April 24, 2022 17:42
Ruby script to download all NCERT book PDFs
# NCERT books are excellent but being altered for political or other reasons
# See: https://twitter.com/SouthAsiaIndex/status/1518062204058103809
# To download the entire current set, run this script with Ruby
require 'httparty'
source = HTTParty.get('https://ncert.nic.in/textbook.php').force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
# book names are like aeen1dd.zip
# First letter tells the class number a to l is class 1 to class 12. m stands for class 11 and 12 combined
@nileshtrivedi
nileshtrivedi / ed25519.sql
Last active February 3, 2023 08:59
ed25519 digital signature methods in PostgreSQL via PL/Python
CREATE EXTENSION IF NOT EXISTS plpythonu;
CREATE FUNCTION py_create_ed25519_keypair ()
RETURNS varchar[]
AS $$
import axolotl_curve25519 as curve
import os
import base64
randm32 = os.urandom(32)
@nileshtrivedi
nileshtrivedi / README.md
Created December 3, 2022 09:39
Ruby on Rails helpers for Apple M1 for missing libpq or missing libidn
brew install libpq
bundle config build.pg --with-pg-config="$(brew --prefix)/opt/libpq/bin/pg_config"

brew install icu4c
brew install libidn
bundle config build.idn-ruby --with-idn-dir="$(brew --prefix)"
@nileshtrivedi
nileshtrivedi / README.md
Created August 15, 2022 04:22
Self-hosting Tutorial 2022

Why self-host?

Not only does it give you control of your own data, it also enables you to explore the amazing possibilities of computation, free from restricted environments like mobile/tablet/desktop/laptop operating systems. As you increase your technical skills and capabilities, you can then use those to solve problems for your own communities.

What do you need?

Familiarity with English language, willingness to learn, and a credit/debit card.

Steps

@nileshtrivedi
nileshtrivedi / computer.rb
Created October 5, 2011 16:30
A simple virtual machine to experiment with minimal instruction sets
# My attempt to implement a simple virtual machine with a minimal instruction set
# 8-bit computer, fixed-size memory, single cpu, 0-registers, based on von-neumann architecture
# No support for interrupts or I/O although we cheat and provide a "print" instruction :)
# The goal is to find a minimal, but turing-complete, instruction set
# For simplicity, every instruction has two operands, which are located adjacent to it in the memory
# This code is just to experiment with various instruction sets and not to be taken seriously
# Next fun step would be to develop a language/compiler for this virtual machine
class Memory
def initialize(size, program)
@nileshtrivedi
nileshtrivedi / puzzle.rb
Created June 25, 2022 12:25
"I don't know the numbers": a math puzzle
# My solution to a cool math puzzle
# Two numbers are chosen randomly, both are positive integers smaller than 100. Sandy is told
# the sum of the numbers, while Peter is told the product of the numbers.
# Then, this dialog occurs between Sandy and Peter:
# Peter: I don’t know the numbers.
# Sandy: I don’t know the numbers.