Skip to content

Instantly share code, notes, and snippets.

View gbersac's full-sized avatar

Guillaume Bersac gbersac

  • 42
  • Paris
  • 02:30 (UTC -12:00)
View GitHub Profile
@gbersac
gbersac / sort_map.java
Created November 14, 2014 16:44
Sorting Map by value.
package misc;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
public class ArrayTools
{
private static class ValueComparator<K , V extends Comparable<V>> implements Comparator<K>
{
@gbersac
gbersac / sub_string.rs
Last active August 29, 2015 14:17
Sub string for rust
pub fn sub_string(model: &String, begin: usize, len: usize) -> Option<String>
{
let mut to_return = String::with_capacity(len);
let mut end = begin + len;
if begin > model.len(){
return None;
}
if begin + len > model.len(){
end = model.len() - begin;
@gbersac
gbersac / rust_iterator_error.rs
Last active October 13, 2017 10:08
rust error while trying to change an iterator
let my_vector = Vec<i32>::new();
for it in my_vector{
it.a = 100; // error: error: use of moved value: `to_return`
}
@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
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):
# 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))
<syntaxhighlight lang="python">
</syntaxhighlight>
@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
// 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
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 =>