Skip to content

Instantly share code, notes, and snippets.

View anandankm's full-sized avatar

Anandan anandankm

  • The MathWorks
  • Natick, MA
View GitHub Profile
@anandankm
anandankm / test
Last active December 25, 2015 16:39
1
import java.util.HashMap;
/*
The Integer Knapsack Problem (Duplicate Items Permitted). You have n types of
items, where the ith item type has an integer size si and a real value vi. You are trying to fill a knapsack of
total capacity C with a selection of items of maximum value. You can add multiple items of the same type
to the knapsack.
s = {3,1,2,4}
v = {4,1,3,2}
@anandankm
anandankm / StreamSample.java
Created December 12, 2012 16:03
Stream sample: based on an evenly distributed random sample.
/**
* Stream sample: based on an evenly distributed random sample.
*/
public class StreamSample
{
private static int sampleSize = 500;
private static int streamCount = 0;
private static int sampleIndex = 0;
private StreamElement[] streamSample = new StreamElement[sampleSize];
@anandankm
anandankm / QueueFrom2Stack
Created November 27, 2012 06:20
A Queue using an additional stack (both the stacks are allocated in the heap)
import java.util.Stack;
public class QueueFrom2Stack<E> {
Stack<E> stack = new Stack<E>();
Stack<E> popStack = new Stack<E>();
public void push(E element) {
this.stack.push(element);
}
@anandankm
anandankm / QueueFromStack
Created November 27, 2012 06:18
A Queue using a stack. This uses an additional stack from the stack memory through recursion.
import java.util.Stack;
public class QueueFromStack<E> {
Stack<E> stack = new Stack<E>();
public void push(E element) {
if (this.stack.empty()) {
this.stack.push(element);
} else {
@anandankm
anandankm / processUploadedFile
Created April 18, 2012 23:47
Processing uploaded file
66 public static function processUploadedFile($data)
67 {
68 $pw = new Product_Worker();
69 $id = $data['ingestionId'];
70 error_log("ingestionId: $id");
71 $pw->ia = DB_Factory::getInstance("Ingestion");
72
73 if (!$pw->isDataReady($id)) {
74 return false;
75 }