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
;; http://grimoire.arrdem.com/ | |
;;shows how to define lambda expressions in clojure | |
;;one form is a shortcut | |
(defn empty? [string] | |
(every? #(Character/isWhitespace %) string)) | |
;; this one is a little more explicit | |
(defn empty2? [string] | |
(every? (fn [x] (Character/isWhitespace x)) string)) |
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
;; CLOJURE STM USING REFS | |
;; this is just an immutable declaration | |
(def some-numbers #{1 2 3}) | |
;;if you want to make the above mutable, you can use "refs" | |
(def some-numbers (ref #{1 2 3 })) | |
;; @ is used to dereference data | |
(def current-some-numbers @some-numbers) |
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
quicksort :: (Ord a) => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = | |
let small = quicksort [ a | a <- xs, a <=x] | |
large = quicksort [ a | a <- xs, a > x] | |
in small ++ [x] ++ large |
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
import scala.Array.canBuildFrom | |
import org.apache.lucene.analysis.standard.StandardAnalyzer | |
import org.apache.lucene.document.Document | |
import org.apache.lucene.document.Field | |
import org.apache.lucene.document.TextField | |
import org.apache.lucene.index.DirectoryReader | |
import org.apache.lucene.index.IndexWriter | |
import org.apache.lucene.index.IndexWriterConfig | |
import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser |
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
//Imports for Dispatch | |
import dispatch._ | |
import Defaults._ | |
object Places { | |
def main(args: Array[String]) { | |
//Step 1 : Prepare the request object |
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
//CASE CLASSES | |
case class Location(lat: Double, lng: Double) | |
case class Geometry(location: Location) | |
case class RunningStatus(open_now: Boolean) | |
case class Results(geometry: Geometry, icon: Option[String], id: Option[String], name: Option[String], | |
opening_hours: Option[RunningStatus], price_level: Option[Double], rating: Option[Double], | |
reference: Option[String], types: Option[List[String]], vicinity: Option[String]) | |
case class RootJsonObject(results: List[Results]) | |
//JSON imports |
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
def main(args: Array[String]) { | |
//Step 1 : Prepare the request object | |
//even though its a https . doing a .secure is not required | |
val request = url("https://maps.googleapis.com/maps/api/place/nearbysearch/json") | |
val requestAsGet = request.GET //not required but lets be explicit | |
//Step 2 : Set the required parameters | |
val builtRequest = requestAsGet.addQueryParameter("key", "Almost gave away my key") |
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
name := "Places Demo" | |
version := "0.1" | |
scalaVersion := "2.10.2" | |
libraryDependencies ++= Seq( | |
"net.databinder.dispatch" %% "dispatch-core" % "0.11.1", //Dispatch is a wrapper over async http library from apache | |
"org.json4s" %% "json4s-native" % "3.2.9", //json4s support for working with json serialization/deserialization | |
"org.json4s" %% "json4s-jackson" % "3.2.9") |
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 get-average-height | |
[people] | |
(let [people-with-height (filter #(contains? % :height) people) | |
heights (map #(:height %1) people-with-height) | |
total (count people-with-height)] | |
(/ (reduce + heights) total))) | |
(defn get-average-height2 | |
[people] | |
(let [people-with-heights (filter #(contains? % :height) people)] |
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 class StringMessageThrottler | |
{ | |
//Subject acts as the message bus. It is a IObservable<string> in our case. | |
private readonly ISubject<string> _eventObservables = new Subject<string>(); | |
private readonly IObservable<string> _distinctPropertyChanged; | |
public StringMessageThrottler() | |
{ | |
var eventsAggregatedForHalfSecond = _eventObservables.Buffer(TimeSpan.FromMilliseconds(500), Scheduler.ThreadPool); | |
//get the unique properties that were changed within the buffered time |