Skip to content

Instantly share code, notes, and snippets.

nileshtrivedi / parrondo.rb
Created Jan 2, 2021
Simulation of Parrondo's Paradox
View parrondo.rb
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)
nileshtrivedi / chatbot.rb
Last active Oct 27, 2020
A stateful chatbot to capture data in 50 lines of Ruby
View chatbot.rb
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"}
View html-mocker.js
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 /
Last active Jun 10, 2020
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 /
Created May 12, 2020
WorldView : A personal beliefs management system


This is the idea for an app I have wanted to build for many years. This would be a database of personal beliefs (also known as a "Propositional Knowledge Base"), connected via logical arguments of various kinds: deductive, inferential and Bayesian. Any new facts you learn should update the certainties of the involved beliefs and propagate that through the graph. You could build a social network around it, giving all users a chance to learn from each other's worldview. This would also help one detect inconsistencies and contradictions. The challenge here is to allow local contradictions without blowing up the system as Principle of Explosion implies.

Related links:

nileshtrivedi /
Last active Sep 15, 2021
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:

I already have my own domain name: 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.


To bring some sanity to your twitter feed, add these words to your muted list here:

Needless to say, this is highly subjective and may not be applicable to how you want to use Twitter. Many of these conversations are important, but I have those on other platforms, not Twitter.

Other people's likes



nileshtrivedi /
Last active May 28, 2021
My thoughts on making the Web more composable like UNIX

The Composable Web Proposal

Serverless infrastructure like AWS Lambda and Google Cloud Functions have made it much cheaper for developers to offer server-side code for public consumption without keeping a server always running.

If these functions could be declared as stateless or deterministic, costs can be brought down even more because only the first invocation needs to be executed. Cached response could be returned for future invocations with the same input arguments.

All modern browsers support URL lengths of thousands of characters, even on mobile. A lot of data can be embedded and passed around directly in the URLs (instead of passing identifiers which requires a look-up which costs server time).

So here's a thought:

nileshtrivedi /
Last active Jan 8, 2019
HyperTrack Onboarding
HyperTrackCore.requestLocationPermissions(this, new LocationPermissionCallback() {
public void onLocationPermissionGranted() {
// Handle location permission granted
public void onLocationPermissionDenied() {
// Handle location permission denied
nileshtrivedi /
Created Jun 18, 2018
Cloud Firestore - Python example
# This script can be used standalone
# So it doesn't depend on filesystem or Google Cloud for the credentials
from import firestore
from google.oauth2 import service_account
key = 'your_credentials_json_string'
info = json.loads(key)
creds = service_account.Credentials.from_service_account_info(info)