Skip to content

Instantly share code, notes, and snippets.

View bmaggi's full-sized avatar

Benoit Maggi bmaggi

  • Bordeaux, France
View GitHub Profile
@bmaggi
bmaggi / gh-pages.md
Created March 25, 2018 19:12 — forked from ramnathv/gh-pages.md
Creating a clean gh-pages branch

Creating a clean gh-pages branch

This is the sequence of steps to follow to create a root gh-pages branch. It is based on a question at [SO]

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" > index.html
@bmaggi
bmaggi / SysML14Constraints.MD
Last active May 18, 2018 16:26
SysML14Constraints.MD

Conform [1] The general classifier must be an element stereotyped by Viewpoint.
Conform [2] The specific classifier must be an element that is stereotyped by View.\

Expose [1] The client must be an element stereotyped by View.\

View [1] A view must only conform to a single viewpoint.
View [2] The derived value of the viewpoint is the classifier stereotyped by Viewpoint that is the general classifier of the generalization relationship stereotyped by Conform for which the View is the specific classifier.
View [3] The derived values of the stakeholder attribute are the names of the classifiers stereotyped by Stakeholder that are the values of the stakeholder attribute of the general classifier of the generalization relationship stereotyped by Conform for which the View is the specific classifier.\

Viewpoint [1] The derived values of the method attribute are the names of the methods of the operations stereotyped by the UML Create stereotype on the classifier stereotyped by Viewpoint.\

@bmaggi
bmaggi / ModelValidationTest
Created October 24, 2017 15:19
A Parameterized Junit test used in an eclipse test fragment to check that all emf models are valid.
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.junit.Assert;
import org.junit.Test;
@bmaggi
bmaggi / Node.java
Created August 1, 2018 11:19
Some unfinished tests about StackOverflowError with recursive implementation
/**
* On an online test the recursive method exited with
* java.lang.StackOverflowError
*
* I suppose that the while should have worked better
* but my local test only exit with java.lang.OutOfMemoryError: GC overhead limit exceeded for both implem
*
* TODO: limit jvm parameters to get the StackOverflowError
*
*/
@bmaggi
bmaggi / AddMultAssociativityLimit.scala
Created October 15, 2018 11:34
In scala floating addition/multiplication are commutative but not associative with big numbers
// floating addition/multiplication are commutative but not associative with big numbers
val small = 1e-200
val big = 1e200
val invBig = -big
(big +invBig)+small // Double = 1.0E-200
big+(invBig+small) // Double = 0.0
List(big,invBig,small).reduceLeft(_+_) // Double = 1.0E-200
List(big,invBig,small).reduceRight(_+_) // Double = 0.0
@bmaggi
bmaggi / GenericPatternNotMatghing.scala
Created October 16, 2018 15:17
In Scala: Pattern Matching not working with List[T]
case class A()
case class B()
val b1 = B()
val b2 = B()
val sB = Seq[B](b1,b2)
sB match {
case _:Seq[A] => println("niet")
case _:Seq[B] => println("da")
@bmaggi
bmaggi / RenameSerialization.scala
Created October 22, 2018 14:50
Simple serialization/deserialization with renaming field in Scala
import org.json4s.FieldSerializer._
import org.json4s.jackson.Serialization
import org.json4s.{DefaultFormats, FieldSerializer}
case class Data(id: Int)
implicit val format = new DefaultFormats {} + FieldSerializer[Data](
renameTo("id", "@id"),
renameFrom("@id","id")
)
@bmaggi
bmaggi / TimeChange.java
Created April 5, 2019 15:49
Example of date change (France,Brasil)
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.TimeZone;
class TimeChange {
public static void main(String[] args) throws ParseException {
timeForward("Europe/Paris", "2019-03-31 01:59:59", Duration.ofSeconds(2).toMillis()); // FRANCE +1
@bmaggi
bmaggi / JavaRandom
Last active July 26, 2019 07:11
Java Random primitive generation (basic Api only)
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.time.Instant;
class JavaRandom {
public static void main(String[] args) {
@bmaggi
bmaggi / FunIsOptional.java
Created October 9, 2019 09:42
Small reminder that orElse parameter is evaluated
import java.util.Optional;
public class FunIsOptional {
public static void main(String[] args) {
Integer i = 0;
System.out.println(Optional.of(i).map(v -> v++).orElse(i--));
// => res = 0 (orElse is evaluated even when not empty)
}