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
View GitHub Profile
@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());
@kedarmhaswade
kedarmhaswade / hanoi.js
Last active August 29, 2015 14:18
towers of brahma (hanoi)
var hanoi = function (disks, src, aux, dst) {
if (disks > 0) {
hanoi(disks-1, src, dst, aux);
console.log("Move disk: " + disks + " from: " + src + " to: " + dst);
hanoi(disks-1, aux, src, dst);
}
}
//hanoi(3, "1", "2", "3");
/*
var stack = [];
@kedarmhaswade
kedarmhaswade / jsonp.html
Created April 7, 2015 01:21
demo of jsonp with github api
<html>
<head>
<script type="text/javascript">
function foo(response) {
var meta = response.meta;
var data = response.data;
console.log(meta);
console.log(data);
}
> var male=false;
undefined
> var salutation;
undefined
> if (male) {
...     salutation = 'Mr.';
... } else {
...     salutation = 'Mrs.';
... }
@kedarmhaswade
kedarmhaswade / .ruby-gemset
Last active August 29, 2015 14:18
notes from Speaking JS by Axel Rauschmayer
speakingjs-md
@kedarmhaswade
kedarmhaswade / ToString.java
Created April 2, 2015 20:23
Use Random.nextLong, but still unscientific
class ToString {
public static void main(String[] args) {
System.out.println("Unscientific benchmark, but out of curiosity");
long t1, t2;
java.util.Random r = new java.util.Random();
long i = r.nextLong();
t1 = System.nanoTime();
String s = "" + i;
t2 = System.nanoTime();
System.out.println(s + " using + on string: " + (t2-t1));