Skip to content

Instantly share code, notes, and snippets.

@srikumarks
srikumarks / vectors_ws1.jl
Last active June 23, 2024 10:30
Sample PlutoJL worksheet for basics of 2D vectors
### A Pluto.jl notebook ###
# v0.19.42
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
@srikumarks
srikumarks / ebonds_extract.py
Last active March 16, 2024 12:45
Electoral bonds pdf to csv extraction
import re
from pypdf import PdfReader
import pandas as pd
# 34ca61ebc3ddbb71a1d16f8f43db38d031872126 encashment-details.pdf
encashment = PdfReader("encashment-details.pdf")
# 11e0aff1007065d9a4de49ac5499fbf4186dcda0 purchaser-details.pdf
purchaser = PdfReader("purchaser-details.pdf")
@srikumarks
srikumarks / mandel.jl
Last active May 18, 2023 15:02
Julia mandelbrot for benchmarking against Python/Mojo
function mandelbrot_kernel(c, max_iter)
z = c
for i in 1:max_iter
z = z * z + c
if abs2(z) > 4
return i-1
end
end
return max_iter
@srikumarks
srikumarks / exploring-measurements.ipynb
Created April 15, 2023 09:25
Trying to understand what "measurement" means in quantum mechanics.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@srikumarks
srikumarks / birthpos.jl
Created January 23, 2023 05:18
Calculating your "birth position"
using Dates, TimeZones, SatelliteToolbox
"""
upcoming_birthpos gives you the exact time and date within the
next year, at which the earth arrives again closest to where it
was when you were born (relative to the sun). It also gives
this minimum distance value in km.
"""
function upcoming_birthpos(y,m,d,h,min,s,tzstr="Asia/Kolkata")
dob = ZonedDateTime(y,m,d,h,min,s,0,TimeZone(tzstr))
@srikumarks
srikumarks / datelang.pl
Last active June 23, 2022 10:21
Miniature date language data generator
:- module(qd, [gendata/0, nth/5, weekday/2, direction/2, dayprop/2, today/1, gendates/4, leapyear/1, nonleapyear/1, validate/1, cardinal/3]).
:- use_module(library(clpfd)).
% This module defines a small query language for (approximate) dates according
% to the gregorian calendar. You can run this program using --
% swipl -t gendata datelang.pl
% Abstract
% ========
@srikumarks
srikumarks / phone-number-encoding.jl
Created October 7, 2021 16:15
Julia port of Norvig's program for number->word translation
using DataStructures
# Ref: https://github.com/renatoathaydes/prechelt-phone-number-encoding
# This is a straight translation of Norvig's program into Julia.
# Function for function it is a straight port.
mappings = [("eE",0),("jnqJNQ",1),("rwxRWX",2),("dsyDSY",3),("ftFT",4),("amAM",5),
("civCIV",6),("bkuBKU",7),("lopLOP",8),("ghzGHZ",9)]
char2num = Dict((l,d) for (s,d) in mappings for l in s)
@srikumarks
srikumarks / async_await_callbacks.js
Created September 13, 2018 15:19
Supporting NodeJS style callbacks using async/await
// Usage is like -
//
// let x = await task(obj, obj.method, arg1, arg2);
// do_something(x);
//
// where obj.method is a method that takes a NodeJS style callback
// as the last argument, which is left out when making the above call.
// The task function turns the callback backed function into a
// pseudo promise which the async/await mechanism can work with.
function task(target, fn, ...argv) {

Keybase proof

I hereby claim:

  • I am srikumarks on github.
  • I am srikumarks (https://keybase.io/srikumarks) on keybase.
  • I have a public key ASDxkdOO0jW8Il1zHH4CO79kv6lEx4tXYvlOA9CosHx7WAo

To claim this, I am signing this object:

@srikumarks
srikumarks / fd-thumbrule-histogram.js
Last active July 28, 2020 15:32
Freedman-Diaconis thumb rule for number of bins of a histogram
// metric = array of real numbers (like > 100 or something)
// IQR = inter-quaartile-range
function numBins(metric, defaultBins) {
var h = binWidth(metric), ulim = Math.max.apply(Math, metric), llim = Math.min.apply(Math, metric);
if (h <= (ulim - llim) / metric.length) {
return defaultBins || 10; // Fix num bins if binWidth yields too small a value.
}
return Math.ceil((ulim - llim) / h);
}