This file contains 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
trait Functor[F[_]] { | |
def map[A,B](fa: F[A])(f: A => B): F[B] | |
def distribute[A,B](fab: F[(A, B)]): (F[A], F[B]) = | |
(map(fab)(_._1), map(fab)(_._2)) | |
def codistribute[A,B](e: Either[F[A], F[B]]): F[Either[A, B]] = e match { | |
case Left(fa) => map(fa)(Left(_)) | |
case Right(fb) => map(fb)(Right(_)) | |
} |
This file contains 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
#!/bin/sh | |
#fix_brew.sh - mcartier | |
#you can keep ur brew if u need ur formulas | |
if [ "$1" = "--keep" ]; | |
then | |
echo "actual brew not removed"; | |
else |
This file contains 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
trait RNG { | |
def nextInt: (Int, RNG) // Should generate a random `Int`. We'll later define other functions in terms of `nextInt`. | |
} | |
object RNG { | |
// NB - this was called SimpleRNG in the book text | |
case class Simple(seed: Long) extends RNG { | |
def nextInt: (Int, RNG) = { | |
val newSeed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFFL // `&` is bitwise AND. We use the current seed to generate a new seed. |
This file contains 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 class Query[D <: Database, +A](db: D, ec: ExecutionContext)(private val atomic: Connection => A) extends Logger { | |
def map[B](f: A => B): Query[D, B] = | |
Query(db, ec)(f compose atomic) | |
def flatMap[B](f: A => Query[D, B]): Query[D, B] = | |
Query(db, ec)(connection => f(atomic(connection)).atomic(connection)) | |
def zip[B](query: Query[D, B]): Query[D, (A, B)] = | |
flatMap { a => |
This file contains 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
// from : http://jonasboner.com/real-world-scala-dependency-injection-di/ | |
case class User(name: String) | |
trait UserRepositoryComponent { | |
val userRepository: UserRepository | |
trait UserRepository { | |
def authenticate(username: String, password: String): User | |
def create(user: User): Unit | |
def delete(user: User): Unit |
This file contains 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
#! /bin/sh | |
# You have to be at the root of the package of the project from which you | |
# want to install the rpm | |
projectName=api_intranet | |
projectNameLong=intranet-parcel-defect-process | |
target="ftops-recette-apiserverintranet-a-01.archinext.local" | |
# Create rpm | |
cat version.sbt | tr - _ > temp && mv temp version.sbt |
This file contains 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
<syntaxhighlight lang="python"> | |
</syntaxhighlight> |
This file contains 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
# example from http://www.johnwittenauer.net/machine-learning-exercises-in-python-part-1/ | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import os, sys | |
def computeCost(X, y, theta): | |
inner = np.power(((X * theta.T) - y), 2) | |
return np.sum(inner) / (2 * len(X)) |
This file contains 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 numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import os | |
def computeCost(X, y, theta): | |
inner = np.power(((X * theta.T) - y), 2) | |
return np.sum(inner) / (2 * len(X)) | |
def gradientDescent(X, y, theta, alpha, iters): |
This file contains 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
> Origin | |
[,1] [,2] [,3] [,4] | |
[1,] 52 30 49 28 | |
[2,] 30 50 8 44 | |
[3,] 49 8 46 16 | |
[4,] 28 44 16 22 | |
> round(X,5) | |
[,1] [,2] [,3] [,4] | |
[1,] 265.2557 0.0000 0.00000 0.00000 | |
[2,] 0.0000 104.8846 0.00000 0.00000 |