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 System; | |
public static class HelloWorld{ | |
public static void Main(){ | |
Console.WriteLine("Welcome to Gist!"); | |
} | |
} |
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
[TestFixture] | |
public class TestEventThrottling | |
{ | |
[Test] | |
public void EventsAreThrottled() | |
{ | |
var fq = new Frequent(); | |
int counter = 0; | |
fq.PropertyChanged += (s, e) => { counter++; }; | |
foreach (var prop in Enumerable.Range(0, 200)) |
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
/// Krishna Vangapandu | |
public class Frequent : INotifyPropertyChanged | |
{ | |
private string _property; | |
private readonly StringMessageThrottler _stringMessageThrottler; | |
public Frequent() | |
{ | |
//Create a new message throttler. The implementation for this would be shown later. | |
_stringMessageThrottler = new StringMessageThrottler(); |
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 |
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
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
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
//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
//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
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 |
OlderNewer