Skip to content

Instantly share code, notes, and snippets.

View MishaelRosenthal's full-sized avatar

Mishael Rosenthal MishaelRosenthal

View GitHub Profile
@MishaelRosenthal
MishaelRosenthal / TraversableWithStatistics.scala
Created January 16, 2014 13:57
Adding mean and variance to Scala collections.
package com.liveperson.predictivedialer.common.utils
/**
* Created with IntelliJ IDEA.
* User: mishaelr
* Date: 1/16/14
* Time: 3:12 PM
*/
object TraversableWithStatistics {
implicit class RichTraversable[+A](collection: Traversable[A]){
package com.liveperson.predictivedialer.examples.misc
import scala.util.Random
import scala.collection.mutable
import com.liveperson.predictivedialer.common.utils.TraversableWithStatistics._
/**
* Created with IntelliJ IDEA.
* User: mishaelr
* Date: 1/16/14
@MishaelRosenthal
MishaelRosenthal / BirthdayParadoxUntilSuccess.scala
Created January 16, 2014 14:05
The Birthday problem (paradox) implementation in Scala. http://en.wikipedia.org/wiki/Birthday_problem
package com.liveperson.predictivedialer.examples.misc
import scala.util.Random
import scala.collection.mutable
import com.liveperson.predictivedialer.common.utils.TraversableWithStatistics._
/**
* Created with IntelliJ IDEA.
* User: mishaelr
* Date: 1/16/14
@MishaelRosenthal
MishaelRosenthal / InviteResponse.scala
Created January 21, 2014 13:17
Usage example for Scala Json writing and reading using Spray. The example includes: Polymorphism, nested case classes, case objects, external libraries classes (FiniteDuration), lists.
package com.liveperson.predictivedialer.common.sessions
import scala.concurrent.duration.FiniteDuration
/**
* User: michaelna
* Date: 1/15/14
* Time: 2:58 PM
*/
object InviteResponse {
@MishaelRosenthal
MishaelRosenthal / ContainsIntervalsTest.scala
Last active January 4, 2016 19:19
Finding all the intervals that contain a given interval.Two implementations are given and tested.1) Using TreeSets and ranges (from, and until).2) Using HashSets and groupBy on all the values of all the intervals.
package com.liveperson.predictivedialer.examples.misc
import scala.util.Random
import scala.collection.immutable.{HashSet, SortedSet, TreeSet}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{Matchers, FlatSpec}
/**
* Created with IntelliJ IDEA.
@MishaelRosenthal
MishaelRosenthal / ScalaCheckExample.scala
Last active November 12, 2018 18:07
An example of usage of the ScalaCheck and ScalaTest frameworks.
package com.liveperson.predictivedialer.examples.misc
import org.scalatest.junit.JUnitRunner
import org.scalatest.prop.Checkers
import org.scalacheck.Prop._
import org.scalacheck.Arbitrary._
import org.scalacheck.Arbitrary
import org.scalacheck.Gen
import scala.collection.immutable.{HashSet, SortedSet, TreeSet}
import org.junit.runner.RunWith
@MishaelRosenthal
MishaelRosenthal / IncrementalStatistics.scala
Created March 4, 2014 17:43
A Scala implementation and testing of incremental mean and variance calculation. Also includes a pimp my library implementation for general Iterable collection.
package com.liveperson.predictivedialer.common.utils
/**
* Created with IntelliJ IDEA.
* User: mishaelr
* Date: 3/4/14
* Time: 7:18 PM
*
* This object contains static methods that can be used for calculating mean in variance incrementally.
* Based on the following:
package com.liveperson.predictivedialer.examples.misc
/**
* Created with IntelliJ IDEA.
* User: mishaelr
* Date: 3/23/14
* Time: 11:50 AM
*
* A two pass implementation
* http://www.cs.yale.edu/homes/el327/datamining2011aFiles/ASimpleAlgorithmForFindingFrequentElementsInStreamsAndBags.pdf
@MishaelRosenthal
MishaelRosenthal / BinarySearch.scala
Last active August 29, 2015 13:57
Binary search on a sorted array
package com.liveperson.predictivedialer.examples.misc
import scala.math.Ordering
import scala.annotation.tailrec
/**
* Created with IntelliJ IDEA.
* User: mishaelr
* Date: 3/26/14
* Time: 2:47 PM
@MishaelRosenthal
MishaelRosenthal / private_keys.pl
Last active August 29, 2015 13:58
A (not so good) perl script that sets ssh keys in host.
#!/usr/bin/perl
use Getopt::Long;
#use File::chdir;
use Cwd;
GetOptions ('host=s' => \$host, 'user=s' => \$user)
or die("Usage: perl private_keys.pl --user <user name> --host <host name>\n");
print "user $user, host $host\n";
my $originDir = getcwd;