Skip to content

Instantly share code, notes, and snippets.

@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 / 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
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: https://twitter.com/nileshtrivedi/status/1521395909535404032 -->
<!-- Chrome team's blog post announcing ElementInternals from 2019: https://web.dev/more-capable-form-controls/ -->
<!-- Importing shoelace.style for the sl-rating element used below -->
@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 / 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 / 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)
end
end
@nileshtrivedi
nileshtrivedi / chatbot.rb
Last active October 27, 2020 07:29
A stateful chatbot to capture data in 50 lines of Ruby
# https://medium.com/cleartax-engineering/a-simple-rule-based-stateful-chatbot-for-data-capture-ebfad9271388
require 'ostruct'
# Track the current state of the conversation
state = {pointer: ""}
# Metadata is used to fill the outgoing templates AND store the captured data from conversation
metadata = {name: "Calvin"}
@nileshtrivedi
nileshtrivedi / html-mocker.js
Last active July 11, 2020 09:32
HTML Mocker
/*
This is an idea for mocking HTML data that lets you test whether your layout breaks on any screen size for any
unexpected dynamic data.
This script scans the document for class names with a specific pattern and periodically randomizes the content
of those elements while meeting the constraints specified in the class name. This can let you quickly test
whether your layout breaks for any dynamic content that you may not have thought about. This should ideally be used
with a responsive design testing tool such as DevTools or Sizzy/Bizzy.
@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.