Skip to content

Instantly share code, notes, and snippets.

public class Solution {
public ArrayList<String> anagrams(String[] strs) {
// Start typing your Java solution below
// DO NOT write main() function
if(strs.length < 2) return new ArrayList();
HashMap<String, ArrayList<String>> map = new HashMap();
for(String str : strs) {
String key = sortChars(str);
// Use built in or binary modules
var crypto = require('crypto');
var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64");
@gabhi
gabhi / app.js
Created June 17, 2014 08:44 — forked from arvis/app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http')
, mongoose = require('mongoose')
, path = require('path');
@gabhi
gabhi / encrypt_decrypt.js
Created August 27, 2014 22:21 — forked from csanz/encrypt_decrypt.js
Encryption decryption in node js
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
public class FilteredIterator<T> implements Iterator<T> {
private Iterator<? extends T> iterator;
private Filter<T> filter;
private T nextElement;
private boolean hasNext;
/**
* Creates a new FilteredIterator using wrapping the iterator and returning only elements matching the filter.
*
* @param iterator
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
@gabhi
gabhi / findKCLosestElement.java
Last active August 29, 2015 14:06 — forked from pavelnganpi/findKCLosestElement.java
Find k closest elements to a given value
public class FindKClosestElementToAGivenValue {
public static int binarySearch(int[] arr,int low, int high, int x){
int mid = 0;
while(low<=high){
mid = (high+low)/2;
if(arr[mid] == x){
return mid;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
// Given a stream of unsorted integers, find the median element in sorted order at any given time.
// http://www.ardendertat.com/2011/11/03/programming-interview-questions-13-median-of-integer-stream/
public class MedianOfIntegerStream {
public Queue<Integer> minHeap;
public Queue<Integer> maxHeap;
@gabhi
gabhi / 01.repl.txt
Last active August 29, 2015 14:13 — forked from ceteri/01.repl.txt
$ ./bin/spark-shell
14/04/18 15:23:49 INFO spark.HttpServer: Starting HTTP Server
14/04/18 15:23:49 INFO server.Server: jetty-7.x.y-SNAPSHOT
14/04/18 15:23:49 INFO server.AbstractConnector: Started SocketConnector@0.0.0.0:49861
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 0.9.1
/_/
<?php
$mongodb = new Mongo("mongodb://username:password@localhost/database_name");
$database = $mongodb->database_name;
$collection = $database->collection;
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$limit = 12;
$skip = ($page - 1) * $limit;
$next = ($page + 1);
$prev = ($page - 1);