Skip to content

Instantly share code, notes, and snippets.

View krishnabhargav's full-sized avatar

Krishna Vangapandu krishnabhargav

View GitHub Profile
@krishnabhargav
krishnabhargav / build.sbt
Created November 12, 2014 13:46
atmosphere/nettosphere build.sbt
libraryDependencies ++= Seq(
"org.atmosphere" % "atmosphere-runtime" % "1.0.4",
"org.atmosphere" % "nettosphere" % "2.1.9")
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
@krishnabhargav
krishnabhargav / websockettestclient.html
Created November 12, 2014 13:48
simple web socket test client
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="text/javascript">
var socket = new WebSocket("ws://localhost:8080/echo");
socket.onopen = function () {
console.log("Connected");
socket.send('hello, world!');
@krishnabhargav
krishnabhargav / monad-examples.lhs
Last active August 29, 2015 14:10
monad examples that helped me understand .. in haskell
Functor & Fmap.
---------------
Lets start with fmap. fmap is defined in a Functor.
fmap takes a function and a box.
fmap then extracts the content from the box,
applies the function on the content and puts the result back into the box.
The signature of the fmap is
> fmap :: Functor f => (a -> b) -> f a -> f b
@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")
@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 / 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)
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 / 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
@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
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