Skip to content

Instantly share code, notes, and snippets.

View gbersac's full-sized avatar

Guillaume Bersac gbersac

  • 42
  • Paris
  • 07:15 (UTC -12:00)
View GitHub Profile
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(_))
}
@gbersac
gbersac / fix_brew_42.sh
Created January 28, 2017 16:46
Shell to update brew sur mac 42
#!/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
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.
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 =>
// 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
@gbersac
gbersac / publishRpm.sh
Created November 18, 2016 13:52
Creation d'un fichier rpm et installation dans un host distant
#! /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
<syntaxhighlight lang="python">
</syntaxhighlight>
# 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))
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):
@gbersac
gbersac / output
Created April 15, 2015 12:12
Eigen vector implementation in R
> 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