This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder