Skip to content

Instantly share code, notes, and snippets.

@rohitvvv
rohitvvv / ReadRepositoryTest.java
Created March 27, 2015 15:06
ReadRepositoryTest - Sample Test File to read an existing GIT repository using JGIT
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.jgitplayground;
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.lib.Repository;
@rohitvvv
rohitvvv / Main.java
Created January 24, 2016 12:51
CompressDecompress
package com.company;
public class Main {
String str;
String compStr;
Main(String str){
this.str=str;
}
//Str => aaaabbcdddddeeeeeeffffghhhhh
String compress(){
@rohitvvv
rohitvvv / Main.java
Last active June 23, 2016 07:37
LRU Simulation
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by rohit on 2/1/16.
* Program to implement LRU algorithm.
* Min value priority : Indicates lease recently used.
* Max value priority: Indicates recently used.
* I Hit 2 Hit 1 Hit 3 Hit 2 Miss 6
* |1 1| |1 0| |1 3| |1 2| |1 1| |6 3|
@rohitvvv
rohitvvv / Main.java
Created January 24, 2016 13:25
BFS
package com.company;
import java.util.Iterator;
import java.util.LinkedList;
public class Main {
private int V; //number of vertices.
private LinkedList<Integer> adj[];
//Constructor that inialises and sets memory for the adj list
Main(int v){
@rohitvvv
rohitvvv / App.java
Created November 25, 2016 07:00
Guava Null Treatmenat and use of Optional
package GauvaDemo;
import static com.google.common.base.Preconditions.*;
import com.google.common.base.*;
import java.util.ArrayList;
import java.util.List;
/**
* Just a snippet on Optional and usage of Preconditions in Guava.
*
@rohitvvv
rohitvvv / App.java
Created December 25, 2016 14:58
Observer Design Pattern
package Observer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Observer design pattern
*/
interface Observer{
@rohitvvv
rohitvvv / init.el
Created January 3, 2017 15:24
Emacs configuration
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar myPackages
public class PrimeSum {
static boolean isPrime(Integer x){
if(x==2)
return true;
if(x%2==0)
return false;
for(Integer j=2;j<=Math.sqrt(x);j++){
if(x%j==0)
return false;
package com.company;
//import java.util.ArrayList;
//import java.util.List;
//class GenerateRandom{
// int range;
// List<Integer> randomNumbers;
// GenerateRandom(int rangeMin,int rangeMax){
// randomNumbers= new ArrayList<>();
// for(int i=0;i<200;i++){
// randomNumbers.add((int)(Math.random()*(rangeMax-rangeMin)));
@rohitvvv
rohitvvv / ScaryFibonacii.clj
Created January 19, 2018 18:25
Scary Fibonacci
(ns overtone.core)
(use 'overtone.live)
(use 'overtone.inst.piano)
(defn fibn
"Find nth fibonacii number"
[n]
(loop [index 0 x 1 y 1]
(if (= index n)
y