Skip to content

Instantly share code, notes, and snippets.

View kedarmhaswade's full-sized avatar
💭
Just trying to catch up with my calendar

Kedar Mhaswade kedarmhaswade

💭
Just trying to catch up with my calendar
  • JyMob
  • Sunnyvale, USA
View GitHub Profile
@kedarmhaswade
kedarmhaswade / Tmp.java
Created April 5, 2016 00:12
Does Java Use the right IP version?
package tmp;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
/**
* Created by kmhaswade on 3/31/16.
@kedarmhaswade
kedarmhaswade / SubsetSum.java
Created March 13, 2016 18:24
SubsetSum using a DP algorithm
import java.util.*;
public class SubsetSum {
public static void main(String[] args) {
subsetHasSum(new int[]{1, 2, 3, 4, 5, 6, 7}, 22);
}
static void subsetHasSum(int[] set, int sum) {
// basic validations
Arrays.sort(set);
System.out.println(Arrays.toString(set));
@kedarmhaswade
kedarmhaswade / DuplicateFinder.java
Created March 6, 2016 02:20
Trying out an SO solution ...
/** Trying out the solution to:
* http://stackoverflow.com/questions/5739024/finding-duplicates-in-on-time-and-o1-space
* Created by kmhaswade on 3/5/16.
* Have I translated @caf's pseudocode correctly?
*/
public class DuplicateFinder {
public static void main(String[] args) throws IOException {
int[] a = new int[]{3, 0, 1, 3, 2};
int n = a.length;
for (int i = 0; i <= n-1; i++) {
/Library/Java/JavaVirtualMachines/8/Contents/Home/bin/java
-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:64661,suspend=y,server=n -ea -Didea.junit.sm_runner -Dfile.encoding=UTF-8
-classpath "/Applications/IntelliJ IDEA 15.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA 15.app/Contents/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/jfxrt.jar:
/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachine
import java.util.*;
class Quicksort {
public static void qsort(int[] ints, int fi, int li) {
/* the recursive procedure */
if (fi < li) {
//int p = partition(ints, fi, li);
int p = partition1(ints, fi, li);
qsort(ints, fi, p - 1);
qsort(ints, p + 1, li);
}
@kedarmhaswade
kedarmhaswade / Lucky.java
Created February 28, 2016 00:17
Lucky Numbers Problem
package tmp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/** <p>
* Find the lucky numbers amongst natural numbers from 1 to n.
@kedarmhaswade
kedarmhaswade / RotateArray.java
Created August 16, 2015 19:10
Rotate an Array
/**
* http://web.stanford.edu/class/cs9/lectures/Coding%20Drill%203.pdf
* Problem One: Array Rotation
* Your job is to write a function
* void rotateArray(int* array, size_t n, size_t amount)
* that accepts as input an array and a “rotation amount.” You should then “rotate” the array
* by cyclically shifting all of the elements in the array to the left by a number of steps
* given by the rotation amount. As an example, suppose we have this array:
* 103 106 107 108 109 110 140 161
* Rotating it to the left by three steps would yield this array:
@kedarmhaswade
kedarmhaswade / SymmetricEncryptionUtility.java
Last active August 29, 2015 14:22
symmetric encryption in Java using 1.8
// based on http://syntx.io/basic-symmetric-encryption-example-with-java/
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.sql.SQLException;
@kedarmhaswade
kedarmhaswade / cascade.js
Last active August 29, 2015 14:18
cascade in JS
// can I implement an object that demonstrates cascading?
"use strict";
var getElement = function() {
var element = {
left_bottom: { x: 0, y: 0},
area: {x: 0, y: 0},
color: 'red'
};
return {
@kedarmhaswade
kedarmhaswade / jstgp.js
Created April 11, 2015 14:40
JS: The Good Parts
Function.prototype.method = function(name, func) {
this.prototype[name] = func;
}
Number.method('integer', function () {
return Math[this < 0 ? 'ceil' : 'floor'](this);
});
console.log((20/6).integer());