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
| column_1 column_2 | |
| mark random | |
| mark something_else | |
| dave | |
| Only care about column_1 uniqueness but want to print out column 2 in the result | |
| Output | |
| 1 dave |
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
| I have a map function which returns the data like this: | |
| Key1 -> Doc1 | |
| Key2 -> Doc2 | |
| Key1 -> Doc3 | |
| What I want to get is: | |
| Key1 -> [Doc1, Doc3] | |
| Key2 -> [Doc2] |
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
| PipedOutputStream poStream = new PipedOutputStream(); | |
| PipedInputStream piStream = new PipedInputStream(); | |
| System.setIn(piStream); | |
| poStream.connect(piStream); | |
| poStream.write("19".getBytes(), 0, 1); | |
| Program.main(); | |
| Program |
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
| Write a function suffixes of type that takes a list xs & returns a list of all the suffixes of xs in decreasing order of length | |
| For example: | |
| suffixes [1, 2, 3, 4] => [[1, 2, 3, 4], [2, 3, 4], [3, 4], [4], []] | |
| Non tail recursive: | |
| let rec suffixes list = | |
| match list with | |
| | [] -> [[]] |
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
| let suffixesTR list = | |
| let rec loop l acc = | |
| match l with | |
| | [] -> acc | |
| | [last] -> loop [] (List.concat [acc; [[last]]; [[]]]) | |
| | hd::tl -> loop tl (List.concat [acc; [l]]) | |
| in | |
| loop list [] |
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
| (defproject test-project "0.1.0" | |
| :description "Test Project" | |
| :dependencies [[org.clojure/clojure "1.2.0"], | |
| [org.clojure/clojure-contrib "1.2.0"]] | |
| :dev-dependencies [[swank-clojure "1.2.0"]]) |
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
| Wanted to understand why this fails to compile: | |
| List(("Mark", 4), ("Charles", 5)).filter(case(name, number) => number == 4) | |
| :1: error: illegal start of simple expression | |
| List(("Mark", 4), ("Charles", 5)).filter(case(name, number) => number == 4) | |
| Yet this works fine: | |
| List(("Mark", 4), ("Charles", 5)).filter{case(name, number) => number == 4} |
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
| (defn yaks [doc] | |
| ; ... | |
| {:tag :Yaks :content[(map (ƒ [s] {:tag :Yak :content [s]}) yaks)] | |
| (defn build-map [doc] | |
| {:tag :meta :content | |
| [{:tag :Foo :content [(xml1-> doc zf/descendants :Bar text)]} | |
| {:tag :Bar :content [(xml1-> doc zf/descendants :Foo text)]} | |
| {:tag :Baz :content [(xml1-> doc :Baz text)]} |
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
| class ContainsElementMatchingCriteria { | |
| def apply[T](allCriteria: Seq[Criteria[T]]) = { | |
| new Matcher[Seq[T]] { | |
| def apply(actual: Seq[T]) = { | |
| MatchResult( | |
| actual.exists((result: T) => allCriteria.forall(_.matches(result))), | |
| "No search result exists with criteria " + allCriteria + " in " + actual, | |
| "An element exists with criteria " + allCriteria + " in " + actual | |
| ) | |
| } |
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
| class Trie | |
| def initialize() | |
| @trie = Hash.new() | |
| end | |
| def build(str) | |
| chars = str.chars | |
| chars.inject(@trie) do |prev, char| | |
| unless prev[char] | |
| prev[char] = Hash.new() |