Skip to content

Instantly share code, notes, and snippets.

@shehaaz
shehaaz / WhatIsASeqView.scala
Last active July 29, 2016 08:17
What is a SeqView in Scala
scala> val seq = (1 to 10000000).view.filter(_ % 2 == 0).map(x => x+1)
seq: scala.collection.SeqView[Int,Seq[_]] = SeqViewFM(...)
scala> seq.take(10)
res0: scala.collection.SeqView[Int,Seq[_]] = SeqViewFMS(...)
scala> seq.take(10).force
res1: Seq[Int] = Vector(3, 5, 7, 9, 11, 13, 15, 17, 19, 21)
scala> val seq = (1 to 10000000).filter(_ % 2 == 0).map(x => x+1)
val time = Latency.measure[Unit](Kamon.metrics.histogram("awesomeHistogram"))
time(printInt(5))
Latency.measure(Kamon.metrics.histogram("awesomeHistogram"))(printInt(5))
def printInt(num: Int): Unit = {
print(num)
}
import java.io.InputStream
import akka.actor.{ Actor, ActorRef, Props, ActorSystem }
case class ProcessStringMsg(lineNumber: Int, fileName: String, string: String, fileSender: Option[ActorRef], listener: ActorRef)
case class StringProcessedMsg(words: Integer, fileSender: Option[ActorRef])
case class FileReference(fileName: String, stream: InputStream)
case class ProcessedFile(fileName: String, totalNumWords: Int, timeElapsed: Long, onCompleteSignal: Boolean)
case class CaptureStream(fileName: String, numOfWords: Int, lineNumber: Int, onCompleteSignal: Boolean)
case class StartProcessFileMsg()
@shehaaz
shehaaz / Options.scala
Created March 28, 2016 04:22
Scala Options Explained
/**
* Option Collections
*
* Some developers see Option as a safe replacement for null values,
* notifying users that the value may be missing and
* reducing the likelihood that its use will trigger a Null PointerException.
* Others see it as a safer way to build chains of operations,
* ensuring that only valid values will persist for the duration of the chain.
*
* The Option type is itself unimplemented but relies on two subtypes for the implementation:
@shehaaz
shehaaz / Optional.java
Created January 5, 2016 21:42
Optional in Java 8
Optional<String> optional = Optional.of("Bam");
if(optional.isPresent())
{
System.out.println(optional.get()); //Bam
}
optional = Optional.empty();
System.out.println(optional.orElse("test")); //test
Rails Active record
create new project
$rails new active_record
create model
$rails g model Manufacturer name:string
generate the game model
$rails g model Game name:string manufacturer:references
Under review as a conference paper at ICLR 2015
MOVE EVALUATION IN GO USING DEEP
CONVOLUTIONAL NEURAL NETWORKS
Chris J. Maddison
University of Toronto
@shehaaz
shehaaz / AnagramChecker.java
Last active August 29, 2015 14:16
Recursive Anagram Checker in Java
static boolean isAnagram(String s1, String s2)
{
//convert string to lower case
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
if(s1.length() != s2.length())
{
return false;
}
{
"header": [
{
"host": "lpas"
},
{
"connection": "close"
},
{
"tesla-version": "2"
>>> list(vertices)
[<Vertex: http://localhost:8182/graphs/graph/vertices/12>, <Vertex:http://localhost:8182/graphs/graph/vertices/40008>]