Skip to content

Instantly share code, notes, and snippets.

View karlmutch's full-sized avatar
🇳🇿
( ಠ ͜ʖಠ)

Karl Mutch karlmutch

🇳🇿
( ಠ ͜ʖಠ)
View GitHub Profile
var (
Web = fakeSearch("web")
Image = fakeSearch("image")
Video = fakeSearch("video")
)
type Search func(query string) Result
func fakeSearch(kind string) Search {
return func(query string) Result {
func init() {
http.HandleFunc("/", errorHandler(betterHandler))
}
func errorHandler(f func(http.ResponseWriter, *http.Request) error) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
err := f(w, r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Printf("handling %q: %v", r.RequestURI, err)
Using Java, with no help from 3rd party libraries, there is the old way and the new way. Just sorting used to be easy with Collections.sort(..).
The challenge with the old way was that a lot of code was required to group the values.
- Input: List<String>
- Output: Map<Character,<List<String>>
- The key of map is 'A' to 'Z'
- Each list in the map are sorted.
Old Java
@karlmutch
karlmutch / gist:221e705051bb56e4cad0
Created May 2, 2015 19:03
This problem comes from a Google+ group and was described as * * You have an array of integers, and for each index you want to find the product of every integer except * the integer at that index. Write a function get_products_of_all_ints_except_at_index() that takes an * array of integers and returns an array of the products.
public static BigInteger [] get_products_of_all_ints_except_at_index(BigInteger [] input)
{
ArrayList<BigInteger> productResults = new ArrayList<BigInteger>(input.length);
BigInteger masterProduct = BigInteger.ONE;
for (BigInteger anItem : input) {
masterProduct = masterProduct.multiply(anItem);
}
for (BigInteger anItem : input) {
36 wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u40-b26/jdk-8u40-linux-x64.tar.gz
37 javac
38 tar xvfo jdk-8u40-linux-x64.tar.gz
39 chown -R root: jdk1.8.0_40
40 sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_40/bin/java 1
41 sudo alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_40/bin/javac 1
42 sudo alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_40/bin/jar 1
43 ls
44 rm jdk
45 rm jdk-8u40-linux-x64.tar.gz