Skip to content

Instantly share code, notes, and snippets.

View lobster1234's full-sized avatar
🎯
Focusing

Manish Pandit lobster1234

🎯
Focusing
View GitHub Profile
@lobster1234
lobster1234 / ProducerConsumerInefficient.java
Last active December 14, 2015 12:39
Producer Consumer - Inefficient (sleep) implementation. Prone to deadlocks.
import java.util.Stack;
public class Bucket {
private Stack<Long> stack = new Stack<Long>();
private int MAX_SIZE = 20;
public Long consume(){
@lobster1234
lobster1234 / ArraySum.java
Last active December 14, 2015 12:48
Test if 2 numbers contained in an array add up to a given number. The time complexity is n(n-1)/2. Space complexity is constant.
public class ArraySum {
private int[] array = new int[]{1,2,3,4,5,6,7,8,9};
/**
* Do any 2 add up to this number
* @param number
* @return
*/
public boolean canAdd(int number){
@lobster1234
lobster1234 / WaitNotifyExample..java
Created March 6, 2013 08:05
A very simple wait/notify example
public class WaitNotifyExample {
public static void main(String[] args) {
Integer lock = new Integer(0);
Thread waiter = new Thread(new Waiter(lock));
waiter.start();
Thread notifier = new Thread(new Notifier(lock));
notifier.start();
}
@lobster1234
lobster1234 / ArraySumWithMap.java
Created March 9, 2013 03:56
Check if a collection contains 2 numbers that add up to the input. This uses a hashmap so that the computational complexity is constant.
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class ArraySumWithMap {
private Map<Integer, Integer> numbers = new HashMap<Integer, Integer>();
/**
@lobster1234
lobster1234 / Binary.java
Created January 11, 2016 06:47
Quick and dirty to convert decimal to binary
public static String binary(int input){
StringBuilder builder = new StringBuilder();
int numerator = input;
while(true){
int divisor = numerator/2;
int remainder = numerator%2;
builder.append(remainder+"");
numerator = divisor;
if(divisor==1){
builder.append("1");
@lobster1234
lobster1234 / docker.md
Last active October 5, 2016 04:53
Notes for docker setup

Installation of Docker Platform (MacOS Sierra)

  • Head to https://docs.docker.com/docker-for-mac/
  • Download the latest docker binary from https://download.docker.com/mac/stable/Docker.dmg
  • Install it (drag and drop)
  • Go to applications, and click on the Docker icon, it will walk you through the rest of the setup.
  • You can notice the docker whale animating in the toolbar at the top right of your mac as it initalizes.
  • You can click that whale to see the current status of docker engine.
  • What has been installed is the docker engine (to manage and run containers), docker machine (the host) and docker compose.
  • We will also need virtualbox, so install it from https://www.virtualbox.org/wiki/Downloads

EC2

  • Can start an AMI to create any number of on-demand instances by using the RunInstances call. Default max is 20 per account.
  • If the request is good, the RunInstances call returns success with a list of DNS names, and instances begin to launch within 10 minutes.
  • The launch request is associated with a reservation ID. One reservation ID can map to multiple instances which are all a part of one launch request.
  • The status can be checked via DescribeInstances call
  • Can be terminated using TerminateInstances call
  • If a running instances uses EBS-backed root volume (boot partition), it can be stopped by StopInstances call. This preseves the data.
  • The same can be done via CLI or the Console instead of REST APIs
  • EBS based root device store will preserve data, hence it is not tied to the life of the instance. Local instance based store presisence is tied to the life of the instance. There is no "stop" option.

Use a tenant_id for each record

What it is

  • Single database running on single instance
  • Every record has a tenant_id as a part of the composite primary key.
  • Application will need to provide this tenant_id for every query as a part of the where clause

Pros

  • One database, one instance
  • Relatively easy to run cross-tenant queries
@lobster1234
lobster1234 / AWS_Certified_Developer_Associate_Sample.md
Last active July 18, 2017 09:04
AWS_Certified_Developer_Associate_Sample.md

My Answers to the Sample Questions provided on the certification site -

You can download the PDF of the questions here

  1. Which of the following statements about SQS is true?
  • A. Messages will be delivered exactly once and messages will be delivered in First in, First out order
  • B. Messages will be delivered exactly once and message delivery order is indeterminate
  • C. Messages will be delivered one or more times and messages will be delivered in First in, First out order
  • D. Messages will be delivered one or more times and message delivery order is indeterminate
@lobster1234
lobster1234 / Solution.java
Last active December 25, 2016 00:16
Code to match brackets - my O(N) submission to HackerRank
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);