Skip to content

Instantly share code, notes, and snippets.

{'publicIdentifier': 'vinothkumar-raman', 'linkedInIdentifier': 'ACoAAAxI2R0BHxz8tYvfEBVyMsNXzKW6edFjPAI', 'memberIdentifier': '206100765', 'linkedInUrl': 'https://www.linkedin.com/in/vinothkumar-raman', 'firstName': 'VinothKumar', 'lastName': 'Raman', 'headline': 'Principal Software Engineer @ Quantman | Built a high performance trading engine', 'location': 'Chennai, Tamil Nadu, India', 'summary': 'Hello, I am VinothKumar Raman. I live in Chennai, India. I have over 15 years of experience building software systems. Particularly large data systems. I am very interested in functional programming languages and type systems.\n I have a ton of experience in Scala, Java, JavaScript and Typescript.\nI have worked on small personal and professional projects Haskell, Purescript, Rust, Zig, Julia, Elixir and Python.\n\nMore on myself and my personal projects here, https://blog.yellowflash.in/about.html', 'photoUrl': 'https://media.licdn.com/dms/image/v2/D5603AQFnT3dX72b9EQ/profile-displayphoto-shrink_800_800/profile-d
@yellowflash
yellowflash / AutoDiff.scala
Created March 13, 2023 05:54
Automatic differentiation, by differed cached evaluation.
object AutoDiff {
// When we are computing derivative for say f(x) we would like to keep track of dx/dt (t being independent variable)
// in-case t == x then diff = 1.
// Suppose x is not a scalar ie., R^k then we would like to keep track of partial derivatives on each co-ordinate.
// Hence V is a vector space (which is just enough for our case), this would be final Jacobian
case class Dual[K, V](value: K, diff: V)
// We define a Vectorspace V over the field K, we can reduce the generalization by keeping K == Double and it should mostly work too.
object Integration {
def integrate(fn: Double => Double,
interval: (Double, Double),
precision: Double = 0.0001): Double = {
def areaBetween(start: Double, end: Double): Double = (fn(end) + fn(start)) / 2 * (end - start)
def doIntegrate(start: Double, end: Double, area: Double): Double = {
val mid = (start + end)/2
val left = areaBetween(start, mid)
val right = areaBetween(mid, end)
class Line {
constructor(m, c) {
this.m = m;
this.c = c
}
apply(x) {
return this.m * x + this.c;
}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine
appendsEx k n c = appends c (zip (iterateN n (rotateBy (1/(fromIntegral k))) unitX) (repeat circ))
circ = (circle 1 # fc red # lc white # lwL 0.25)
sides = 6
@yellowflash
yellowflash / SpatialMap.scala
Last active June 27, 2018 07:56
Spatial Index with geo hash
import scala.annotation.tailrec
import scala.collection.mutable
case class Point(x: Int, y: Int) {
def geoHash(precision: Int): BigInt = {
@tailrec
def hash(minX: Int, maxX: Int, minY: Int, maxY: Int, prec: Int, sofar: BigInt) : BigInt = {
if(prec == 0) return sofar;
val quadrant = if((minX + maxX)/2 < x) {
if((minY + maxY)/2 < y) 0 else 1
@yellowflash
yellowflash / Regex.js
Last active June 27, 2018 12:17
A derivative based regex matching
class Regex {
constructor(matchesEmpty) {
this.matchesEmpty = matchesEmpty;
}
derivativeBy(ch) {
throw "Not implemented";
}
matches(str) {
@yellowflash
yellowflash / Map.js
Created May 16, 2018 15:42
Hash map with linear probing
class Map {
constructor(loadfactor = 0.7) {
this.size = 0;
this.loadfactor = 0.7;
this.entries = new Array(1);
}
put(key, value) {
this.resizeIfNecessary();
for(var i = key.hashCode();; i++) {
@yellowflash
yellowflash / Godel.purs
Last active October 11, 2018 10:14
Purescript implementation of a dependent typed language.
module Godel.Core where
import Control.Monad (bind, pure)
import Control.Monad.Eff.Console (log)
import Data.Either (Either(..))
import Data.Eq (class Eq, (==))
import Data.Map (Map, empty, insert, lookup)
import Data.Maybe (Maybe(..))
import Data.Show (class Show, show)
import Prelude (otherwise, negate, (+), (-), (>=), ($), (<>))
package cont
import scala.util.Try
abstract class Cont[A] {
def run[R](cont: A => R): R
def map[B](fn: A => B): Cont[B] = {
val self = this
new Cont[B] {def run[R](cont: B => R) = self.run(cont compose fn)}
}