Skip to content

Instantly share code, notes, and snippets.

@Ramasubramanian
Ramasubramanian / Task2Sessions.java
Created July 30, 2018 09:48
Constraint Programming Bin Packing example
package com.ajira.chocosolver;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.search.loop.monitors.CPProfiler;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.Variable;
import java.io.IOException;
import java.util.Arrays;
@Ramasubramanian
Ramasubramanian / RealmListParcelConverter.kt
Created March 10, 2017 08:55
A generic kotlin utility class to convert a realm list with parceler
/**
* Java code from https://gist.github.com/patloew/bc32a2a1a3c0097e9c7020192fb2c78f
* used and converted to Kotlin with some modifications
*/
open class RealmListParcelConverter<T> : TypeRangeParcelConverter<RealmList<T>, RealmList<T>> where T : io.realm.RealmObject{
override fun toParcel(input: RealmList<T>?, parcel: Parcel) {
if (input == null) {
parcel.writeInt(NULL)
module LangtonsAnt
type Direction = Up | Down | Left | Right
type CellColor = Black | White
type Cell = {Row: int; Column: int; Color: CellColor; Ant: Ant option}
and Ant = {Cell: Cell; Direction: Direction}
type Plane = {Cells: Cell[][]}
# Path to your oh-my-zsh installation.
export ZSH=/Users/raam/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="random"
# Uncomment the following line to use case-sensitive completion.
@Ramasubramanian
Ramasubramanian / states.json
Last active October 13, 2018 10:40
JSON file for rendring d3js map of India. No license is needed to use this file, but the data here is only for representation purposes and solves my use-case. It may not statistically or geographically accurate and I am not responsible for any issues arising out of these inaccuracies
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Ramasubramanian
Ramasubramanian / LazyUsage2.java
Created February 17, 2014 15:32
Second usage example for Lazy type.
package in.raam.lazy;
import java.util.ArrayList;
import java.util.List;
class Parent {
private String key;
private Lazy<List<Child>> children = Lazy.create(() -> new ParentHelper().loadChildren(this));
public Lazy<List<AnotherChild>> childList = Lazy.create(this::loadChildList);
@Ramasubramanian
Ramasubramanian / LazyTest.java
Created February 17, 2014 15:26
unit test case for Lazy.java
package in.raam.lazy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@Ramasubramanian
Ramasubramanian / LazyUsage.java
Created February 17, 2014 15:20
Usage example of Lazy.java written earlier
package in.raam.lazy;
class IntensiveResource {
public IntensiveResource() {
// e.g.
// obtain a JNDI object may be a datasource or remote objects
// load values from file
// create datasource manually
// load a huge set of children objects for a parent collection
System.out.println("Wait! performing CPU intensive operations...");
@Ramasubramanian
Ramasubramanian / Lazy.java
Last active August 29, 2015 13:56
A toned down implementation of C sharp's Lazy in Java 8
package in.raam.lazy;
import java.io.Serializable;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
/**
@Ramasubramanian
Ramasubramanian / NQueensTree.java
Last active December 19, 2015 11:19
N Queens implementation to identofy all solutions on a Tree based storage instead of generating all combinations of solutions
package nqueens;
import java.util.*;
import nqueens.Tree.Leaf;
import nqueens.Tree.Node;
public class NQueensTree {
static class Count {