Skip to content

Instantly share code, notes, and snippets.

View adilakhter's full-sized avatar

Adil Akhter adilakhter

View GitHub Profile
@adilakhter
adilakhter / binarysearch.scala
Last active August 29, 2015 14:05
Binary Search with Scala
object BinarySearchApp extends App{
BinarySearch.execute(Array(1,2,3))(1) is Some(0)
BinarySearch.execute(Array(1,2,3))(3) is Some(2)
BinarySearch.execute(Array(1,2,3))(10) is None
}
object BinarySearch{
@adilakhter
adilakhter / odata_uri.txt
Last active August 29, 2015 14:12
odata_uri
http://host:port/path/SampleService.svc/Categories(1)/Products?$top=2&$orderby=Name
\______________________________________/\____________________/ \__________________/
| | |
service root URL resource path query options
@adilakhter
adilakhter / tlambda.scala
Created February 10, 2015 12:42
TypeLambda Example
trait Functor[A,+M[_]] {
def map2[B](f: A => B): M[B]
}
object Functor {
implicit class SeqFunctor[A](seq: Seq[A]) extends Functor[A,Seq] {
def map2[B](f: A => B): Seq[B] = seq map f
}
implicit class MapFunctor[K,V1](mapKV1: Map[K,V1]) extends Functor[K,({type λ[α] = Map[α,V1]})#λ] {
def map2[K2](f: K => K2): Map[K2,V1] = mapKV1 map {
@adilakhter
adilakhter / TypeLambdaDemo.scala
Last active August 29, 2015 14:15
TypeLambda #Scala
// Example HList with type member Hd
trait HList{
type Hd
}
class IntList extends HList {
type Hd = Int
}
@adilakhter
adilakhter / DemoClient.java
Last active August 29, 2015 14:20
Demo StatsDClient
import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.StatsDClient;
public class DemoClient {
public static void main(String[] args) throws InterruptedException {
StatsDClient client = new NonBlockingStatsDClient("nc", "127.0.0.1", 8125);
int counter = 100;
client.gauge("activeroute.request",counter);
Requesting....0
Requesting....1
Requesting....2
Requesting....3
Buffer((0,200 OK), (1,200 OK), (2,200 OK), (3,200 OK))
Requesting....4
Requesting....5
Requesting....6
Requesting....7
Requesting....8
@adilakhter
adilakhter / concurrent.md
Created May 19, 2015 18:58
log of concurrent request

Following is the concurrent behaviour:

Iteration 1: No of Concurrent Request 12.  Result: 
 List(200 OK, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 200 OK, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 200 OK, 429 Too Many Requests)
Iteration 2: No of Concurrent Request 12.  Result: 
 List(429 Too Many Requests, 429 Too Many Requests, 200 OK, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests)
Iteration 3: No of Concurrent Request 12.  Result: 
 List(429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 200 OK, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests, 429 Too Many Requests)
Iteration 4: No of Concurrent Request 12.  Result: 
 L
@adilakhter
adilakhter / typelambda.scala
Last active August 29, 2015 14:23
typelambda
case class MapFunctor[K,V](mapKV: Map[K,V])
extends Functor[V, ({type L[a] = Map[K,a]})#L]{
override def map[V2](f: V => V2): Map[K, V2]
= mapKV map{ case (k,v) => (k, f(v))
}
}
Functor[A, +M[_]]
=>
Functor[V,
(
{
type L[a] = Map[K, a] // structural type definition
}
) #L // type projection
]
case class ReadableMapFunctor[K,V](mapKV: Map[K,V]){
def mapFunctor[V2] = {
type `Map[K]`[V2] = Map[K, V2]
new Functor[V, `Map[K]`] {
override def map[V2](f: (V) => V2): `Map[K]`[V2] = mapKV map{
case (k,v) => (k, f(v))
}
}
}