Skip to content

Instantly share code, notes, and snippets.

View andypetrella's full-sized avatar

Andy Petrella andypetrella

View GitHub Profile
@ayosec
ayosec / CORSDirectives.scala
Created December 18, 2012 03:28
CORS with Spray
package foo.bar
import spray.routing._
import spray.http._
import spray.http.StatusCodes.Forbidden
// See https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
case class Origin(origin: String) extends HttpHeader {
@andypetrella
andypetrella / sample-dsl.scala
Last active December 11, 2015 04:18
Un exemple de DSL très simple avec Scala
case class Banque(nom:String) {banque =>
def accepte(m:Montant) =
CompteBuilder(banque, m)
}
implicit def stringToBanque(s:String) = Banque(s)
implicit def intWithDevise(i:Int) = new {
@Thell
Thell / Exmple.Rmd
Created June 20, 2013 23:59
R markdown to illustrate creation of in-document referencing for chunks, sections, pages, and such.
```{r setup, echo=FALSE, results='hide'}
chunkref <- local({
function(chunklabel) {
sprintf('[%s](#%s)', chunklabel, chunklabel )
}
})
secref <- local({
function(seclabel) {
sprintf('[%s](#%s)', seclabel, seclabel )
@helena
helena / ProvisioningActor.scala
Last active December 21, 2015 04:39
Rough, initial cut of a trait to mixin when an Actor requires initalization, where the initialization is long and arduous (for example, data initialization related). This strategy allows the implementing actor to delegate the work to another Actor, on a separate, dedicated Dispatcher, and not block any other related Actors in load-time.
import scala.collection.immutable
import scala.collection.immutable.Queue
import akka.actor._
/**
* Rough, initial cut of a trait to mixin when an Actor requires
* initalization, where the initialization is long and arduous (for
* example, data initialization related). This strategy allows the
* implementing actor to delegate the work to another Actor, on a
* separate, dedicated Dispatcher, and not block any other related
@etrepum
etrepum / Bob.hs
Created August 27, 2013 02:09
One pass Bob parser
module Bob (responseFor) where
import Data.Char (isSpace, isLower, isAlpha)
import Control.Applicative ((<$>), (<*>), (<|>))
data Prompt = Silence | Yell | Question | Other
deriving (Show, Eq)
data P a = P { pCanParse :: Char -> Bool
, pParse :: Char -> Either (P a) (Maybe a)
, pParseEOF :: Maybe a
}
@debasishg
debasishg / gist:8172796
Last active May 7, 2024 22:18
A collection of links for streaming algorithms and data structures

General Background and Overview

  1. Probabilistic Data Structures for Web Analytics and Data Mining : A great overview of the space of probabilistic data structures and how they are used in approximation algorithm implementation.
  2. Models and Issues in Data Stream Systems
  3. Philippe Flajolet’s contribution to streaming algorithms : A presentation by Jérémie Lumbroso that visits some of the hostorical perspectives and how it all began with Flajolet
  4. Approximate Frequency Counts over Data Streams by Gurmeet Singh Manku & Rajeev Motwani : One of the early papers on the subject.
  5. [Methods for Finding Frequent Items in Data Streams](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.187.9800&amp;rep=rep1&amp;t
@pchiusano
pchiusano / partask.scala
Created February 12, 2014 22:10
Applicative for scalaz.concurrent.Task that 'automatically' parallelizes the applicative operations
import scalaz.Applicative
import scalaz.concurrent.Task
/**
* This `Applicative[Task]` runs tasks in parallel, by defining
* `ap` and `apply2` in terms of `mapBoth`. This differs from the
* default `Applicative[Task]`, where effects are sequenced
* deterministically, in left to right order.
*/
val T = new Applicative[Task] {

What is Scala?


Créé par Martin en 2003 -- Son nom vient de l'anglais Scalable language Scala intègre les paradigmes de programmation orientée objet et de programmation fonctionnelle, avec un typage statique


  1. Fonctionnel basique

a) Immutability

model mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1
Duster 360 14.3 8 360 245 3.21 3.57 15.84 0 0 3 4
Merc 240D 24.4 4 146.7 62 3.69 3.19 20 1 0 4 2
Merc 230 22.8 4 140.8 95 3.92 3.15 22.9 1 0 4 2
@cjmatta
cjmatta / spark-notebook_mapr.md
Last active December 22, 2015 02:06
Building and using Spark Notebook for MapR

##Building and using Spark Notebook for MapR

The spark-notebook is a useful browser-based REPL that can be used to explore data and build visualizations. This guide will illustrate the MapR-specific requirements for building, and using the spark notebook on MapR clusters.

###Building Checkout the source:

$ git clone https://github.com/andypetrella/spark-notebook.git