Skip to content

Instantly share code, notes, and snippets.

nileshtrivedi /
Created June 9, 2024 06:18
Generating a 4-player chess board SVG using Python
import svgwrite
def create_4player_chess_board():
# Dimensions and colors
margin = 10
square_size = 40
board_size = 14 * square_size + 2*margin
light_color = '#ebecd0'
dark_color = '#739552'
light_extra_color = '#fdfee3'
nileshtrivedi /
Last active June 18, 2024 08:22
Elixir LiveView Agent Chat Experiment
nileshtrivedi /
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, you can set up your fediverse instance at This will allow your users to have an email address like and fediverse address as It's also possible to run the fediverse instance on your top-level domain (eg: In this case, both the email address and fediverse address will be But users visiting in the browser will directly land on your fediverse instance which can't be customized as much as a proper website can be.
nileshtrivedi /
Created December 3, 2022 09:39
Ruby on Rails helpers for Apple M1 for missing libpq or missing libidn
brew install libpq
bundle config --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 /
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.


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.
nileshtrivedi / web-components-are-not-ready.html
Last active May 3, 2022 07:59
Web Components are not yet ready
<!-- I will consider web components ready for use when this piece of HTML works -->
<!-- Here we import two different WC frameworks and mix custom input elements in a single form -->
<!-- Like regular HTML forms, we expect this form to work without writing any custom Javascript code for data plumbing -->
<!-- Some context: This will be possible in future with ElementInternals api which works in Chrome & Firefox, but not in Safari -->
<!-- See this conversation: -->
<!-- Chrome team's blog post announcing ElementInternals from 2019: -->
<!-- Importing for the sl-rating element used below -->
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:
# To download the entire current set, run this script with Ruby
require 'httparty'
source = HTTParty.get('').force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
# book names are like
# First letter tells the class number a to l is class 1 to class 12. m stands for class 11 and 12 combined
nileshtrivedi / Caddyfile
Created November 14, 2021 18:30
Caddy on as reverse proxy to services on Tailscale network
log stdout
errors stdout
auto_https off {
nileshtrivedi / parrondo.rb
Created January 2, 2021 05:43
Simulation of Parrondo's Paradox
def coin(win) = rand(1000) > (1000 - win) ? 1 : -1
def a(capital) = coin(495) # 49.5% chance of winning
def b(capital) = (capital % 3 != 0) ? coin(745) : coin(95)
def simulate(strategy, count)
(strategy * count).reduce(100) do |capital,game|
capital + send(game, capital)