Skip to content

Instantly share code, notes, and snippets.

View krishnabhargav's full-sized avatar

Krishna Vangapandu krishnabhargav

View GitHub Profile
type State<'S,'a> = 'S -> ('a * 'S)
module State =
let unit a : State<_,_> = fun s -> (a, s)
let map<'s,'a,'b> (f : 'a -> 'b) (r : State<'s,'a>) =
fun s ->
let a,next = r(s)
f(a), next

static T[] Rotate(int n, T[] arr) { var temp = new T[arr.Length]; for (int i = 0; i < arr.Length; i++) { var destIndex = i - n; if (destIndex < 0) { var mul = -1 * destIndex / arr.Length; destIndex = (arr.Length * mul) + destIndex;

@krishnabhargav
krishnabhargav / DiffMerge as Default GIT tool
Created January 24, 2016 23:42
For Windows : Git config commands to set up DiffMerge as default GIT tool.
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'c:/tools/diffmerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'c:/tools/diffmerge/sgdm.exe --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"'
git config --global mergetool.diffmerge.trustExitCode true
1) explain the life of an http request.
2) what does the FLP result teach us?
3) what is a byzantine failure?
4) explain CRDTs
5) explain linearizability.
6) how does DNS work?
7) crash-stop vs crash-recovery?
8) difference between soft and hard real time
9) model GC in an eventually consistent system
10) discuss clock skew, NTP, and AWS vs metal
@krishnabhargav
krishnabhargav / MethodConstraints.fs
Created May 20, 2015 02:06
F# Method Constraints .. multiple ones
let inline recordMetrics< ^T when ^T : (member MessageCountDetails : MessageCountDetails)
and ^T : (member Path : string)> (all : ^T seq) =
recordMetricsForPath (fun e -> (((^T : (member Path : string) e)))) all
@krishnabhargav
krishnabhargav / paket-hello.console
Last active August 29, 2015 14:16
paket hello world
learning/hello-paket/HelloPaket master ✗ 103d ✖ ⚑ ◒
▶ wget https://github.com/fsprojects/Paket/releases/download/0.30.3/paket.bootstrapper.exe
--2015-02-23 21:20:58-- https://github.com/fsprojects/Paket/releases/download/0.30.3/paket.bootstrapper.exe
Resolving github.com... 192.30.252.131
Connecting to github.com|192.30.252.131|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://s3.amazonaws.com/github-cloud/releases/22755810/f2133dfe-bb80-11e4-9f9d-f777da134aed.exe?response-content-disposition=attachment%3B%20filename%3Dpaket.bootstrapper.exe&response-content-type=application/octet-stream&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1424744518&Signature=v8wt6BYpfl2y0QOeTkmPQe18xUE%3D [following]
--2015-02-23 21:20:58-- https://s3.amazonaws.com/github-cloud/releases/22755810/f2133dfe-bb80-11e4-9f9d-f777da134aed.exe?response-content-disposition=attachment%3B%20filename%3Dpaket.bootstrapper.exe&response-content-type=application/octet-stream&AWSAccess
src/Unit-1/DoThis master ✗ 23h17m ◒
▶ ls -l
total 7456
-rw-r--r-- 1 bhargava staff 182 Feb 23 08:16 App.config
-rw-r--r-- 1 bhargava staff 1140 Feb 23 08:16 ConsoleReaderActor.cs
-rw-r--r-- 1 bhargava staff 1092 Feb 23 08:16 ConsoleWriterActor.cs
-rw-r--r-- 1 bhargava staff 1530 Feb 23 08:16 Program.cs
drwxr-xr-x 3 bhargava staff 102 Feb 23 08:16 Properties
-rw-r--r-- 1 bhargava staff 2595 Feb 23 08:16 WinTail.csproj
-rw-r--r-- 1 bhargava staff 960 Feb 23 08:16 WinTail.sln
@krishnabhargav
krishnabhargav / gcd-lcm.fs
Last active August 29, 2015 14:14
GCD/LCM in F#
let rec gcd a b = match (a,b) with
| (x,y) when x = y -> x
| (x,y) when x > y -> gcd (x-y) y
| (x,y) -> gcd x (y-x)
let lcm a b = a*b/(gcd a b)
@krishnabhargav
krishnabhargav / TypeInferenceLambda.fs
Created January 25, 2015 16:30
type inference in F# starts from left to right and top to bottom. So if you do not use |> operator, then type annotations in lambda expression will be required.
let sizeOfFolder folder =
let allFiles = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
let fileInfos = allFiles |> Array.map (fun x -> new FileInfo(x))
let allSizes = fileInfos |> Array.map (fun x -> x.Length)
Array.sum allSizes
///This version requires explicit type annotations in the lambda
let sizeOfFolder2 folder =
let allFiles = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
let fileInfos = Array.map (fun (x:string) -> new FileInfo(x)) allFiles
@krishnabhargav
krishnabhargav / spark-sql-people.scala
Created November 22, 2014 02:25
Spark SQL example ... beautiful...
val sqlContext = new org.apache.spark.sql.SQLContext(sc); //sc is SparkContext
import sqlContext._
case class Person(name: String, age: Int)
val randomPeople = sc.parallelize(1 to 1000).map(i => Person("Yu_"+i,i))
randomPeople.registerAsTable("people")
val aged30 = sql("select * from people where age = 30")