## [Drupal] Service dependency injection in a plugin type class

### The code

• Unlike service type class service dependency injection, there may be no need to implement an interface to be able to load the needed services, such as extending from ControllerBase. So if you are extending from a class which already has the dependency injection implementation, you can just override the create and __construct methods. Don’t forget to call parent methods if needed.
• Think of the create method as the model used by the __construct of your class.
• The create signature needs to respect the one of the implemented interface (use your IDE to check against the original declaration).
• Originally made and tested on Drupal 8.2.x.
• A convenient list of core services can be found here: https://api.drupal.org/api/drupal/core%21core.services.yml/8.2.x (don’t forget to select the Drupal version if you are not on 8.2.x).
• Some classes such as ones extending BlockBase will need to implement interfaces to access this pattern:

## Mini point sur ma carrière

J’ai quitté volontiers l’industrie du jeu vidéo, ayant perdu toute motivation d’y travailler. L’entreprise dans laquelle j’avais passé plus de quatre ans à essayer de produire des jeux et des applications est sur le point de fermer définitivement. Un chapitre de ma vie est en train de se clore, j’imagine.

Avais-je dit que j’étais rentré en France il y a quelques mois ? Bon, ben c’est fait. J’avais la tête tellement dans le cul que j’ai oublié de le mentionner. Je n’ai rien trouvé de pertinent sur Montréal hormis des éventuels boulots de testeur dans le jeu et l’applicatif. Pour un game designer et développeur, ce n’est pas très sérieux et j’ai écouté les conseils de proches m’invitant à arrêter l’expérience.

Avec le recul, je pense pouvoir dire que se dédier aux jeux vidéo, dans l’état actuel du monde, c’est le mode difficile des carrières. J’ai côtoyé de nombreuses personnalités, des personnes sympathiques et ouvertes, et leurs contraires menteurs ou indolents. Mais surtout, j’y ai vu de la précarité. La mienne déjà, et surtout les autres et la pléthore de témoignages trouvables sur la toile. Et le temps qui défile, inlassablement.

Durant ce parcours du combattant, j’ai utilisé de nombreuses techniques et outils de développement :

• développement logiciel : Virtools 5, Unity en UnityScript puis en C#, un coup de Java sur Android, Cocos2D-x en C++
• art : Illustrator, Photoshop, Premiere Pro, After Effects, Blender, FLStudio
• sites web : HTML5, PHP5 (OOP uniquement), CSS, LESS, un soupçon de Javascript et de jQuery, un chouilla de SQL, quelques notions d’Apache
• IDE : Visual Studio, Xcode, Eclipse, Android Studio
• outils divers : SVN, Git, Mercurial, SourceTree, JIRA, VirtualBox, 5 navigateurs desktop, 2 navigateurs mobiles

Une bonne partie d’entre eux appris en autodidaxie, par passion comme on pourrait le dire. Mais apparemment, cela ne suffit pas à convaincre lorsque j’avais voulu rentrer dans le rang après une longue période en indépendance. Trop généraliste ? Pas d’expérience ? Des entretiens foireux ? Les raisons m’empêchant de retourner à l’emploi dans ce secteur sont nombreuses et je n’ai pas le temps ni l’envie de les énumérer ici. Par contre, je n’ai pas vraiment essayé de tirer profit de mon réseau professionnel. Bien que réduit, il aurait pu aboutir à quelque chose, mais encore une fois, il s’agit de probabilités. Je suis du genre à vouloir expérimenter par moi-même, me prouver que je peux convaincre grâce à ce que j’ai fait par le passé, sans utiliser d’artifices. Et force est de constater que c’est un beau fail.

### Et ensuite ?

Je reste intéressé par le jeu vidéo, mais de manière plus diffuse et personnelle ; ayant toujours des projets en cours et aimant réfléchir à des designs. Mais le travail en équipe, c’est terminé.

À partir d’aujourd’hui, je vais commencer à écrire des articles à propos de Drupal, l’outil qui va être dans quelques semaines mon principal centre d’intérêt technologique ! En effet, j’ai rejoint une formation de type Préparation Opérationnelle à l’Emploi Individuelle grâce à Pôle Emploi dans un organisme de formation qui s’appelle Trained People. Moi qui pensais ne plus vouloir y remettre les pieds chez Pôle Emploi, décidément.

L’écosystème Drupal est si différent de celui des outils du jeu vidéo. Déjà, l’approche open source m’a toujours attiré. Je me rends bien compte à quel point le jeu vidéo est un milieu basé sur le secret, où chacun veut protéger sa petite idée de peur de se faire voler l’idée du siècle. Bien sûr, tout n’est pas parfait, notamment sur Drupal et sa documentation imbuvable. Mais voir un tel effort collectif pour faire fonctionner des milliers de modules contribués gratuitement, ça reste un point qui me donne envie de mettre la main à la pâte.

Étrangement, malgré une expérience bien foireuse ici en intérim juste avant, tout se passe à merveille depuis décembre 2016, c’est-à-dire dès que je suis entré dans le processus de recrutement de la formation.

## [Android] Remove “Couldn’t add widget” from the Overview Screen (Lollipop 5.1)

Enraged

After having spent more than a day on the matter, I have finally figured out how to remove the Couldn’t add widget block in the Overview Screen. This is the block which appears in place of the Google search bar on top of the recent apps list after you have disabled the Google app.

### Step by step

1. Open the Play Store.
2. Install KISS Launcher.
5. Touch the Home button.
6. Set the KISS Launcher as default launcher.
7. Reboot in Safe Mode (the process may differ on your Android OS):
1. press the power button,
2. long touch on the Power Off button,
3. touch OK.
8. When the reboot is done, the Google bar should have returned in the Overview Screen.
• On this step, the bar wasn’t interactable on my phone.
9. Power off normally your device.
11. When the reboot is done, the Google bar should still be in the Overview Screen.
12. Go to Settings > Apps > ALL.
13. Disable the Google app. Accept everything when it says it will uninstall updates and data.
14. Touch the Home button.
15. Wait a few seconds.
16. Open the Overview Screen.
17. Enjoy!

• I have succeeded two times on a nearly fresh install of Android 5.1 (Lollipop) on a Moto E.
• I have updated a lot of native apps until the internal storage was full (yes, on the 1st gen Moto E 4GB, you cannot have all the default apps up to date with the tiny internal storage space).
• A lot of websites and user feedback will tell you to just restart in Safe Mode to remove the bar. It did not do the trick on my phone for some reason.
• I had to try a lot of possibilities so I don’t remember exactly what are the triggers for the bar removal. My guess is a combination of the KISS Launcher as default launcher app, a Google App up to date before disabling, and reboots between Safe Mode and normal mode, and maybe a full internal memory.
• The only apps disabled when the bar removed itself after the disabling were:
• Assist (by Motorola)
• Motorola Migrate
• Help (by Motorola)
• Email (the default Android app)
• The only apps enabled but not up to date were:
• Google Play Movies & TV
• Maps – Navigation & Transit
• Motorola Camera
• The remaining apps were up to date.
• Third party apps installed from the Play Store:
• Amaze File Manager
• SuperSU
• Third party apps installed from the SD Card includes:
• I did not remove KISS Launcher afterwards because I like it. But feel free to change to another launcher. I guess it will work.
• Pour les francophones, la méthode démontrée ci-dessus indique comment retirer le bloc avec le message « Impossible d’ajouter le widget » dans l’écran « Overview » qui affiche la liste des applications récentes (gestionnaire de tâches).
• The step by step needs to be more accurate so I am wishing to get some feedback.

## Unity3D.tips[2]: Intersection point between two lines in 2D

### The maths behind

To get the point where two lines intersect, we will do some maths. To the mathematicians who will come across this post, I’m truly sorry for the heart attacks or strokes you may experience by reading this post.

Ok, let’s take a look on the figure:

First, sorry, I was too lazy to make a proper figure using computer tools so I just put a scan. XD

Next, here are the definitions:

• $A$ & $B$: the two lines,
• $A_1, B_1$: the arbitrary starting points of the two lines,
• $A_2, B_2$: the arbitrary points which tells the direction of the two lines,
• $X$: the intersection point,
• $O$: the origin point.

Kewl. Now, what we want is the intersection point $X$ between those two lines. In other words, we want to know the position which starts from either lines’ arbitrary starting point, added by the direction of the line multiplied by a scalar value. So in our figure 1, the $X$ position is:

• the $A_1$ position added by the components of $\overrightarrow{A_1A_2}$ multiplied by an unknown which I named $\lambda$
• the $B_1$ position added by the components of $\overrightarrow{B_1B_2}$ multiplied by an unknown which I named $\mu$

In this case, it is clear that $\lambda = \mu = 0.5$ so it will be easy to check if our final formula is correct. 🙂

At the point of intersection, we know that:
$\begin{array}{rcl} \overrightarrow{OX} = \overrightarrow{OA_1} + \lambda\times\overrightarrow{A_1A_2} & and & \overrightarrow{OX} = \overrightarrow{OB_1} + \mu\times\overrightarrow{B_1B_2} \end{array}$

… which gives us:
$\begin{array}{rcl} \overrightarrow{OA_1} + \lambda\times\overrightarrow{A_1A_2} & = & \overrightarrow{OB_1} + \mu\times\overrightarrow{B_1B_2} \\ \overrightarrow{OA_1} - \overrightarrow{OB_1} & = & \mu\times\overrightarrow{B_1B_2} - \lambda\times\overrightarrow{A_1A_2} \end{array}$

But we can’t use this statement exactly like this to solve our equation as we cannot multiply and divide vectors in this raw format. Also we need to reduce the unkowns count to 1. So we will separate our equation into two equations with the magic of matrices (which I don’t understand well at the moment), one for the x component and one for the y:
$\left\{\begin{array}{c} \overrightarrow{OA_1}_x - \overrightarrow{OB_1}_x = \mu\times\overrightarrow{B_1B_2}_x - \lambda\times\overrightarrow{A_1A_2}_x \\ \overrightarrow{OA_1}_y - \overrightarrow{OB_1}_y = \mu\times\overrightarrow{B_1B_2}_y - \lambda\times\overrightarrow{A_1A_2}_y \end{array}\right.$

To make our equation more readable, we will use some shorthands:
$\begin{array}{r}A_\alpha = \overrightarrow{A_1A_2}\end{array}\\ \begin{array}{r}B_\alpha = \overrightarrow{B_1B_2}\end{array}\\ \begin{array}{r}C = \overrightarrow{OA_1} - \overrightarrow{OB_1}\end{array}$

… so:
$\left\{\begin{array}{c} C_x = \mu B_{\alpha x} - \lambda A_{\alpha x} \\ C_y = \mu B_{\alpha y} - \lambda A_{\alpha y} \end{array}\right.$

From this point, we can reduce the unknown count. In my case, I have chosen to keep $\mu$ instead of $\lambda$:
$\left\{\begin{array}{c} C_x A_{\alpha y} = \mu B_{\alpha x} A_{\alpha y} - \lambda A_{\alpha x} A_{\alpha y} \\ C_y A_{\alpha x} = \mu B_{\alpha y} A_{\alpha x} - \lambda A_{\alpha y} A_{\alpha x} \end{array}\right.\\ \begin{array}{rcl} C_x A_{\alpha y} - C_y A_{\alpha x} & = & \mu B_{\alpha x} A_{\alpha y} - \lambda A_{\alpha x} A_{\alpha y} - (\mu B_{\alpha y} A_{\alpha x} - \lambda A_{\alpha y} A_{\alpha x}) \\ C_x A_{\alpha y} - C_y A_{\alpha x} & = & \mu B_{\alpha x} A_{\alpha y} - \lambda A_{\alpha x} A_{\alpha y} - \mu B_{\alpha y} A_{\alpha x} + \lambda A_{\alpha y} A_{\alpha x} \\ C_x A_{\alpha y} - C_y A_{\alpha x} & = & \mu B_{\alpha x} A_{\alpha y} - \mu B_{\alpha y} A_{\alpha x} \\ C_x A_{\alpha y} - C_y A_{\alpha x} & = & \mu (B_{\alpha x} A_{\alpha y} - B_{\alpha y} A_{\alpha x}) \\ \mu & = & \frac{C_x A_{\alpha y} - C_y A_{\alpha x}}{B_{\alpha x} A_{\alpha y} - B_{\alpha y} A_{\alpha x}} \end{array}$

And finally, you have to check if $B_{\alpha x} A_{\alpha y} - B_{\alpha y} A_{\alpha x} = 0$. This will happen if your two lines are parallel or if there is one line defined as a point such as $A_1 = A_2$ or $B_1 = B_2$; no solution exists in those cases.

#### Test 1

Kewl! Now let’s try it with the Figure 1:
$\begin{array}{rcl} \mu & = & \frac{(1 - 1) \times 1 - (2 - 4) \times 2}{2 \times 1 - (-3) \times 2} \\ \mu & = & \frac{4}{8} = 0.5 \end{array}$

We can get the $X$ position:
$\left\{\begin{array}{l} \overrightarrow{OX}_x = \overrightarrow{OB_1}_x + B_{\alpha x} \times \mu = 1 + 2 \times 0.5 = 2 \\ \overrightarrow{OX}_y = \overrightarrow{OB_1}_y + B_{\alpha y} \times \mu = 4 + (-3) \times 0.5 = 2.5 \end{array}\right.$

#### Test 2

Ok done! Now let’s try with another figure:

$\begin{array}{rcl} \mu & = & \frac{((-2) - 2) \times (-1) - ((-2) - (-3)) \times 0}{(-1.5) \times (-1) - 1.5 \times 0} \\ \mu & = & \frac{4}{1.5} \approx 2.666 \end{array}$

We can get the $X$ position:
$\left\{\begin{array}{l} \overrightarrow{OX}_x = \overrightarrow{OB_1}_x + B_{\alpha x} \times \mu = 2 + (-1.5) \times 2.666 = -2 \\ \overrightarrow{OX}_y = \overrightarrow{OB_1}_y + B_{\alpha y} \times \mu = (-3) + 1.5 \times 2.666 = 1 \end{array}\right.$

## Unity3D.tips[1]: Strategies to prevent the collision when a ball rolls from a planar surface to another

### Method 1: mega box collider

Use a single BoxCollider for all your planes. For example, if you have multiple aligned planes, remove their Collider component (Box, Mesh, whichever they have) and on only one of the planes, add a BoxCollider and adjust its center and size values in the component’s inspector to encapsulate all the planes.

• Simple.

#### Cons

• Supports only rectangular surfaces.

### Method 2: generated colliders

If you are rolling your ball on a non rectangular surface, you will need to find a way to generate a mesh collider for all your planes. For this, choose one of the following:

• Just works.

#### Cons

• Uses noticeable CPU power when updating (baking) the colliding mesh in real time. Update sparingly.

### Method 3: ramps as bridges

Create a set of meshes from a 3D software such as Blender to make invisible ramps which will be placed partly underground between your planes. They have to be large enough to make the transitions as smooth as possible. The height between the top of the bridge and the ground (the planes) should be approximately the value defined by the Default Contact Offset value in the Physics Manager.

#### Pros

• No real improvement.

#### Cons

• The ball may jump a little, especially at high speed.
• Doesn’t work with small tiling (or when your successive planes are small): the longer the tiles, the longer bridges can be.
• Requires a lot of testing.
• Requires 3D software usage.
• The result is not consistent.
• Requires good workflow / toolchain.

### Method 4: make custom extended planes’ colliders

This one should not work very well.

Create in a 3D software a planar mesh. Then, on its edges, extrude towards outside and lower down slightly the new edges. To put the words into image:

Make them intersect, and hopefully the bouncing will be invisible.

#### Pros

• Quite simple.

#### Cons

• The ball may jump a little, especially at high speed.
• Requires a lot of testing.
• Requires 3D software usage.
• The result is not consistent.
• Requires good workflow / toolchain.

### Method 5: turn slightly your planes’ colliders

Make your planes’ colliders slightly rotated so that, in the direction of movement, the end of a collider is slightly above the next plane’s collider. The height should be approximately the value defined by the Default Contact Offset value in the Physics Manager and hopefully no bouncing will occur.

#### Pros

• Works flawlessly.

#### Cons

• You will see the ball flying and falling a few units from one plane to another.

### Method 6: do everything by script

Maybe the Physics is not what is the best for your gameplay. Write your own system with accelerations, collision detection. This is the old-fashioned way and is the choice of a lot of developers! ^^

#### Pros

• Works flawlessly.
• Permits game design driven gameplay and not by physics.

#### Cons

• Not using the PhysX forces and gravity.
• Requires to work (omg! 😉 ) to simulate fake physics.

### Method 7: Make your ball much larger

By using a greater ball (x10, x100), this could lead to less edge detection.

• May work.

#### Cons

• The scale of the simulation would change: if you make everything at the same scale as the ball, objects falling by gravity will look like they fall in slow motion.
• The result is not consistent.

### Method 8: collision layers and raycast

This one is pretty cool.

1. Keep single BoxColliders for each plane. Set the layer of the plane prefab to SinglePlanes (create the layer).
2. Make a big Unity cube with a collider which encapsulates all the planes. Set the layer of the cube to ContinuousPlane.
3. Create two layers: OnAPlane and NotOnAPlane.
4. Set the ball prefab’s layer to OnAPlane.
5. In Physics Manager, set the collision matrix so that:
• NotOnAPlane and ContinuousPlane are not collidable (unchecked),
• OnAPlane and SinglePlanes are not collidable (unchecked).
6. On each Update(), do a raycast from the center of the ball towards Vector3.down on the layer SinglePlanes:
7. If the raycast returns false, the center of the ball is not on a plane. So now, we change the layer of the ball to NotOnAPlane. The ball will start to fall through the hole.
8. If the raycast returns true, set the layer of the ball to OnAPlane.

For how to define a layer, please check the manual.

#### Pros

• Works efficiently with dynamic floor layout.
• You will learn how to deal with layers and Physics.

#### Cons

• No real flaws.

• Methods above may be combined.
• You can adjust the physics project settings and / or set the physics materials to reduce the bounciness of your objects.
• Make sure the thickness of the planes collision is not 0f. Make them 1f large or more.
• There is a possibility to reduce the bounces, but I am not recommending it (may cause jittery and physics artifacts): set the Default Contact Offset to 0.0001. Again, I am not recommending it!
• All of this post could be useless when the default PhysX embedded in Unity will be upgraded.
• I originally posted this post as an answer on the Unity Answers website but none of the above methods have been considered as valid by the OP. Hence the removal from the answers website.

## Unity3D.tips[0]: Avoid naming your MonoBehaviour methods Main()

Try to avoid naming your MonoBehaviour methods Main(). These would be triggered between Awake() and Start(). This Main() method supports IEnumerator flavors as much as Awake() and alike! But as useful as it could be, I would not recommend to use it as there is no official documentation entry in the manual. And usually, you should not need this method.

Évitez de nommer Main() les méthodes se situant dans vos MonoBehaviour. Celles-ci seraient déclenchées entre Awake() et Start(). Cette méthode Main() supporte la version en IEnumerator autant que Awake() et les autres ! Mais aussi utile que pourrait être cette méthode, je ne la recommanderais pas à l’usage puisqu’il n’existe aucune documentation officielle dans le manuel. Et normalement, vous ne devriez pas avoir recours à cette méthode.

## [Windows-10] Why some photos are not appearing in the Photos live tile

Partie française plus bas

### Symptoms

If you are using Windows 10, you may want to pin the Photos live tile to the Start Menu. But some of the images from your pictures folders are not showing in the live tile, or even worse, no picture is displayed on the live tile.

You have tried (or not) the suggestions on the Microsoft forums like those on this thread: thread on Microsoft Answers website.

### Solution

The last thing you could try before reinstalling or giving up (or switching to another OS) is this:

Pictures you want in the Photos live tile have to be 620px × 620px minimum.

I have spent a few hours to find the info about the problem on the internet but none of the websites I have visited have mentioned the size prerequisite. That’s why if you stumble upon my tip and your photos are now displaying correctly on your Photos live tile, do not hesitate to share this. 😉

• The images used by the Photos live tile are located here:

You will find that your images have shrunk until the width or the height of the image was 620px.
• If an image is not “compatible” with the live tile, it will not appear here.
• When you update the contents of your images folders, it looks like there is a listener which will update automatically the images list of the Photos tile.

Partie française

### Symptômes

Si vous utilisez Windows 10, vous pourriez avoir envie d’épingler la vignette dynamique de l’application Photos au Menu Démarrer. Mais certaines images de votre dossier d’images ne s’affichent pas dans la vignette dynamique, ou même pire, aucune image ne s’affiche dans cette vignette dynamique.

Vous avez essayé (ou pas) les suggestions des forums de Microsoft telles que celles sur ce fil de discussion : fil de discussion sur le site Microsoft Answers (anglais).

### Solution

Voici une dernière chose que vous pouvez tester avant de réinstaller le PC ou d’abandonner (ou de changer d’OS) :

Les images que vous désirez voir apparaître dans la vignette dynamique de Photos doivent mesurer 620px × 620px minimum.

J’ai passé quelques heures à chercher l’information sur internet mais aucun des sites web n’avaient indiqué un quelconque prérequis concernant la taille. C’est pourquoi si vous tombez sur mon site et que vos photos apparaissent enfin dans votre vignette dynamique, n’hésitez pas à partager cette information. 😉

• Les images utilisées par l’application Photos se trouvent ici :

Vous trouverez que vos images ont été rétrécies jusqu’à ce que la largeur ou la hauteur fait 620px.
• Si votre image n’est pas compatible avec la vignette dynamique, elle n’apparaîtra pas ici.
• Lorsque vous mettez à jour les contenus de vos dossiers d’images, il semblerait qu’il y ait un écouteur (listener) qui mettra à jour automatiquement la liste des images de la vignette dynamique de Photos.

## [Linux] Use GRUB from a previously installed Linux in a dual boot setting

When you install a new Linux alongside another one, your computer will likely use the last installed OS’s GRUB instead of the one from the previous install.

In my case, I have installed Debian, and a few days later, a Linux Mint on the same disk. But the thing is I prefer the Debian’s GRUB because it is prettier, with a nice image background! Also, I want to keep Debian as my default choice on boot. I could have modified the boot order via Grub Customizer (I will let you Google that) but still! The Debian’s GRUB is better than the Ubuntu’s (Linux Mint’s) dark and ugly one. 😛

### Step by step

To use the old install’s GRUB, use those commands from the old OS (Debian for me):

• … with the X corresponding to your disk of installation. For example: sudo grub-install /dev/sda

• Then reboot and enjoy!

I hope this helps! I have found those steps on the Ubuntu’s documentation: https://help.ubuntu.com/community/Grub2/Installing

## [Debian] Japanese IME in GNOME 3 desktop

Surprised

The japanese IME on Debian, when installed properly, works pretty much similarly to the Windows 7 one… I was quite surprised by the quality of this software piece.

### Step by step

1. Install those packages from official repositories: ibus and ibus-mozc (along with their dependencies, of course).
2. Launch the Region & Language settings app.
3. In Input Sources, click on the + sign.
4. Search for the Japanese (Mozc) input source and add it.
5. You are ready to use the IME. 🙂 Quickly switch between input sources with Super (Windows key) + Space.

Okay, it’s possible it will not work on your side. I have done some other steps but I am not sure if they were useful or not (I started from a near fresh install). If the steps above didn’t work, you may have to open the Input Method app. Then click on Yes, Yes. Select ibus and click OK. Then OK again. Then restart your computer. From there, you should be able to add the Japanese (Mozc) input source in the Region & Language settings app.

Some day, I will try to redo those steps in a virtual machine to make sure the steps are working… Until then, 幸運を祈ります！