Skip to content

Instantly share code, notes, and snippets.

View MastaP's full-sized avatar

Pavel Grigorenko MastaP

View GitHub Profile
@MastaP
MastaP / SleepingTest.java
Created December 7, 2018 11:43
A JUnit test which succeeds with TC 1.8.0 and hangs indefinitely on 1.9.0 and 1.10.2
import java.io.Closeable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.Description;
import org.slf4j.Logger;
import org.testcontainers.containers.GenericContainer;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.Frame;
@MastaP
MastaP / NatNumSequence.java
Created October 2, 2012 16:45
DevClub.eu programming challenge (Oct. 2012)
package eu.devclub;
import java.util.*;
public class NatNumSequence {
public static int getNthDigit(long index) {
if(index < 1) throw new IllegalArgumentException( "Not a natural number" );
if(index < 10 ) return (int) index;
@MastaP
MastaP / Graph.java
Created April 10, 2012 22:20
Computing strongly connected components (SCCs)
package org.coursera.algo;
import java.util.*;
public abstract class Graph<V extends AbstractVertex<E>, E extends AbstractEdge<V>> {
private final TreeMap<Integer, V> vertices = new TreeMap<Integer, V>(
new Comparator<Integer>() {
//for pretty printing
@Override
@MastaP
MastaP / MinCut.java
Created April 5, 2012 21:02
Finding minimum cuts in undirected graph using contraction algorithm
import java.io.*;
import java.util.*;
/**
* https://class.coursera.org/algo/quiz/attempt?quiz_id=52
*/
public class MinCut {
private static class Graph {
@MastaP
MastaP / QuickSort.java
Created April 2, 2012 13:06
QuickSort with 4 pivoting strategies
public class QuickSort {
private interface PivotStrategy {
public void selectPivot(int[] a, int p, int r);
}
private final static PivotStrategy PIVOT_ON_FIRST = new PivotStrategy() {
@Override
public void selectPivot(int[] a, int p, int r) {
//do nothing
@MastaP
MastaP / Inversions.hs
Created March 14, 2012 11:21
Counting inversions
--module AlgoClass where
import Data.List (elem, permutations)
import System.IO
import System.CPUTime
--Week 1
--Merge Sort
mergesort :: Ord a => [a] -> [a]