Skip to content

Instantly share code, notes, and snippets.

@wgpshashank
wgpshashank / MemoizationAverage.rb
Created September 16, 2011 23:26
Snippets of code I've written recently to various programming challenges
#Problem= Given N, arrange all numbers from 1 to N such that the average of any two numbers in the list #does not lie between them.
#if this doesn't run, "gem install memoize" add sudo in front if you don't use RVM to manage your gems
require 'rubygems'
require 'memoize'
require 'benchmark'
include Memoize
def good_list(n)
@wgpshashank
wgpshashank / Auto-Suggestion
Created October 17, 2011 07:09
How Google Won User's Heart :: Google Auto-Suggestion/Auto-Completion Algorithm Exposed
How Auto Suggestion Works e.g. How Google Won User's Heart
You've seen search engines suggest queries when you begin typing the first few letters of your search string. This is being done by Duck Duck Go as well as Google (to name a few). This is typically done by maintaining
a list of past queries and/or important strings that the search engine thinks are worthy of being suggested to a user that is trying to find something similar. These suggestions are effective only if the search engine
spits them out very fast since these should show up on the screen before the user has finished typing what he/she wanted to type. Hence the speed with which these suggestions are made is very critical to the usefulness of this feature.
Let us consider a situation (and a possible way of approaching this problem) in which when a user enters the first few letters of a search query, he/she is presented with some suggestions that have as their prefix,
the string that the user has typed. Furthermore, these suggestions should
@wgpshashank
wgpshashank / SumOfCubes
Last active February 6, 2019 05:32
Find the smallest number expressible as the sum of cubes of two numbers in two different ways. Indeed, 10^3 + 9^3 =12^3+1^3=1729 , Do It Efficiently
Problem:
A mathematician G. H. Hardy was on his way to visit his collaborator S. Ramanujan an who was in the hospital. Hardy remarked to Ramanujan that he traveled in taxi cab number 1729 which seemed a dull one and he hoped it was not a bad omen. To this, Ramanujan( Math Guy) replied that 1729 was a very interesting number-it was the smallest number expressible as the sum of cubes of two numbers in two different ways.
Indeed, 10^3 + 9^3 =12^3 + 1^3 = 1729.
Hint: This problem is very similar to another very popular problem that is asked in interviews.
You are given a η ×η matrix in which both rows and columns are sorted in ascending order and you are supposed
to find a given number in the matrix.
Algorithm:
@xaviershay
xaviershay / LdapAuthenticator.java
Created July 24, 2012 03:27
LDAP Authentication for dropwizard
package com.squareup.alcatraz.auth;
import com.google.common.base.Optional;
import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
@nikcub
nikcub / README.md
Created October 4, 2012 13:06
Facebook PHP Source Code from August 2007