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 / 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 / Scratch.java
Last active January 21, 2021 07:48
Split/Unsplit in Java/Scala
import java.util.Arrays;
class Scratch {
public static void main(String[] args) {
System.out.println(Arrays.equals("a".split("b"),("ab".split("b")))); //true
// but
System.out.println("a".equals(unsplit("a".split("b",-1),"b"))); // true
System.out.println("ab".equals(unsplit("ab".split("b",-1),"b"))); // true
@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 / 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 / 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 / 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 / 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 / gist:34ffd351d11137192ac8d5909fbcc74a
Created February 8, 2018 08:27 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@bmaggi
bmaggi / SetPapyrusIcon.java
Last active January 10, 2018 09:45
A utility to set all icon/eannotation for Papyrus images in a profile.
package org.eclipse.papyrus.sysml.tests;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
@bmaggi
bmaggi / NoGenericPredicateFilter.java
Created November 6, 2017 14:19
A simple way to use predicate to filter data structure (also catch the exception)
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* A simple way to use predicate to filter data structure
*
* @author Benoit Maggi