Skip to content

Instantly share code, notes, and snippets.

View sreeprasad's full-sized avatar

Sreeprasad sreeprasad

  • BlackRock
  • New York
View GitHub Profile
@sreeprasad
sreeprasad / LevelOrderTraversal
Created November 16, 2014 18:38
Level Order Traversal LeetCode
public List<List<Integer>> levelOrder(TreeNode root) {
List<List<Integer>> list = new ArrayList<>();
Queue<TreeNode> q = new java.util.LinkedList<TreeNode>();
ArrayList<Integer> level;
if(root!=null){
level = new ArrayList<Integer>();
level.add(root.val);
list.add(level);
q.add(root);
level = new ArrayList<Integer>();
@sreeprasad
sreeprasad / ExampleTwo.java
Created November 22, 2014 12:07
Any method reference of a method that takes no parameters and returns void of a class can be used as code for Thread
public class ExampleTwo {
public static void myExample(){
System.out.println("Hello there, you have reached personal website of Sreeprasad");
}
public static void main(String[] args) {
Thread t = new Thread(ExampleTwo::myExample);
t.start();
}
@sreeprasad
sreeprasad / ExampleOne.java
Created November 22, 2014 12:14
lambda expression to create instance of Runnable interface
Runnable aRunnableObject = () -> System.out.println("Hello CrowdTwist !");
@sreeprasad
sreeprasad / ExampleThree.java
Created November 22, 2014 14:54
Thread Race probelm
public class ExampleThree{
private static int bal=0;
public static void updateBal(){
bal+=10;
bal-=10;
}
public static void monitorBal(){
@sreeprasad
sreeprasad / ThreadJoin.java
Created November 22, 2014 15:40
Call join() method of a thread after it has been started
public class ThreadJoin{
public static void main(String[] args) {
Thread t = new Thread(ThreadJoin::print);
t.start();
try{
t.join();
}catch(InterruptedException e){
System.out.println(e);
@sreeprasad
sreeprasad / about.md
Last active August 29, 2015 14:22 — forked from jasonrudolph/about.md

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@sreeprasad
sreeprasad / System Design.md
Created April 20, 2016 01:25 — forked from vasanthk/System Design.md
System Design Cheatsheet

#System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

##Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?

Introduction

This gist started with a collection of resources I was maintaining on stream data processing — also known as distributed logs, data pipelines, event sourcing, CQRS, and other names.

Over time the set of resources grew quite large and I received some interest in a more guided, opinionated path for learning about stream data processing. So I added the reading list.

Please send me feedback!

@sreeprasad
sreeprasad / SelfExpiringHashMap.java
Created September 13, 2016 10:59
SelfExpiringHashMap - a Java Map which entries expire automatically after a given time; it uses a DelayQueue internally.
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;