W14Y18 – MQTT Client for OSX, Fingerprint & HTTPS, Consola and full width embedded Youtube video

MQTT Client for OSX

For those working with OSX, I suggest you to use the most powerful MQTT client I’ve found: MQTTfx. This soft is complete. You will find all the basic features (like unsecured connection, already available on most light tools) and some very useful:

  • User/password authentication
  • SSL/TLS
  • Proxy settings

You have a large choice of certificates, which covers a lot of scenarios and platforms (SAP IoT 4.0 Platform included)

View/download MQTTfx

Fingerprint Check to verify HTTPS certificates

Sometimes, it can be useful to check if you are sending data or connected to the right website (for security purposes). In my case, when I’m connecting Arduino boards or something like this with network I’m not the owner, I’m using the fingerprint check.

Let’s see how it works.

First, you need to retrieve the fingerprint for the target website/API. For this, go to the website and click on the little “lock” icon in the address bar and click on the Certificate section.

Now, scroll down while you find the Fingerprints section and copy these two values (see below the example with Github).

The last step is to check when you establish the connection, if the fingerprint is the same or not. Below, an example in Arduino

// Check HTTPS
WiFiClientSecure client;
Serial.print("Connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
  Serial.println("Connection failed");
  return;
}

if (client.verify(fingerprint, host)) {
  Serial.println("Certificate matches");
} else {
  Serial.println("Certificate doesn't match");
}
// The rest of your code...

Consola

Logs are important when you code – If you pass your day, switching between terminal windows, it’s time to get them sexy! For this, I found Consola and I fall in love with this elegant consoler logger.

npm install consola --save

And now in your code, you can log info like this:

const consola = require('consola')

// See types section for all available types
consola.start('Starting build');
consola.success('Built!');
consola.info('Reporter: Some info');
consola.error(new Error('Foo'));

Give a try here: https://github.com/nuxt/consola

Full width embedded Youtube video

If you want to embed your Youtube video on your blog (WordPress or other), it’s possible with some custom CSS.

First go to the video link you want to embed and click on Share > Embed and get the whole iframe tag.

For example: <iframe width="560" height="349" src="http://www.youtube.com/embed/<YOUR_VIDEO_ID>" frameborder="0"></iframe>

Now, wrap the iframe tag inside a div and add the css.

<div class="youtubeVideoContainer">
    // the iframe tag here
</div>

.youtubeVideoContainer {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 25px;
    height: 0;
}
.youtubeVideoContainer iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

That’s it. Your video will use the full width of your post.

W09Y18 – Merge images, SAPUI5 Image component, Raspberry Pi SSH over USB

Merge images

If you need to merge mutiples images in one, I’ll warmly recommend you to use this JavaScript library: https://github.com/lukechilds/merge-images.

Yes, I know what you are going to tell me: it’s possible to do it without any library but it’s more complicated, and not easy to maintain. For example, to do the same in pure JavaScript, you have to play with canvas… below a little example:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var imageObj1 = new Image();
var imageObj2 = new Image();
imageObj1.src = "1.png"
imageObj1.onload = function() {
   ctx.drawImage(imageObj1, 0, 0, 328, 526);
   imageObj2.src = "2.png";
   imageObj2.onload = function() {
      ctx.drawImage(imageObj2, 15, 85, 300, 300);
      var img = c.toDataURL("image/png");
      document.write('<img src="' + img + '" width="328" height="526"/>');
   }
};

It’s not as sexy as…

mergeImages(['/body.png', '/eyes.png', '/mouth.png']).then(b64 => document.querySelector('img').src = b64);

Agree? And you have some interesting features:

– positioning (x, y) – opacity – size (width, height)

And it’s under MIT licence.

SAPUI5, fix error 404 on sap.m.Image component

I developed some apps using the SAP UI5 frontend framework and on each app, I have the same errors in the console on each page I use the SAPUI5 Image component (sap.m.Image).

It’s not a blocking point or something really embarrassing but… if someone opens the console, it’s weird.

It’s due to retina support (good intention…) but if you haven’t your images with different densities, it will generate errors (see this article). The solution to avoid this error is to set the densityAware to false.

setDensityAware function.

By default it’s true, but I think that’s bad and should be set to false…

Raspberry Pi Zero & SSH over USB

I realized something very bad: the Raspberry Pi Zero is using a mini HDMI port (see below the HDMI vs mini HDMI)

I was very surprised and little bit blocked because it’s not a adaptor I have in my pocket. Then, I ordered one on AliExpress for less than 2$ (Mini HDMI adaptor).

If you are in the same situation then me, I have a good news, you will not be struggled because you can use your USB to ssh in few easy steps!

Step 1:

On the root of your SD card you have to add the following property at the end of the config.txt file:

dtoverlay=dwc2

Step 2:

On the root of your SD card you have to add the following property just after the rootwait parameter in the cmdline.txt file:

modules-load=dwc2,g_ether

Step 3:

Last step, you have to create a new file named “ssh” without any extension on the root of your SD card. Now connect the Raspberry Pi to your laptop and let it boot. Wait 30 seconds for the RPi to finish the boot, open your terminal and launch the command:

ssh pi@raspberrypi.local

Tadaaaaa

W04Y17 – Git, create a new repository from a current branch, disable HTTP logs in Express, Android mass storage and kill process on specific port

Create a new repo from an existing branch

As you know, it’s strongly recommended to create a new repository if a branch depends to another branch in your project… Basically, if you need to clone a repo twice and checkout each to a different branch to launch your project, it’es very bad!

So, the simplest method in three steps to create a new repo from a current branch is to:

> create your **new_repo** in GitHub
> cd to your local branch 
> git push git@github.com:youraccountname/new_repo +old_branch:master

Now, your new GitHub repository is up to date. The master branch corresponds to the branch in your old repo with all history preserved which is a very good point!

How to disable HTTP request logs in Node/Express.js

When you launch your application built on Node/Express, you’ll probably see a lot of logs for each resources (css, images, js, etc…)

GET /resources/styles.css 200 0ms
GET /js/lib/jmyawesomelib.js 200 0ms
etc...

The solution is to move the logging plugin below the resource plugin in the app init! or comment your morgan module (works on Express.js 4)

//app.use(morgan('dev'));

No more logs!

Mass storage troubleshooting

I figured some problems lorsque je branchais my Google Nexus 5X to my Macbook (also on a Windows machine too). It was impossible to do a mass storage to retrieve the phone content (photos, videos, downloaded files, etc…). I tried all the solutions found on forums and the only software that saved my life is Android File Transfer by Google for OSX.

Download Android File Transfer

Kill process running on a specific port

To kill a port that is running on a specific port, you need to execute the following commands. First, get the list of process running with corresponding ports and info:

netstat -a -o -n

Now, you get a list of process running on your machine, you only have to pick the PID corresponding the port you are looking to kill and replace 8080 below.

taskkill /F /PID 8080

Successfully killed, bye bye πŸ™‚

W38Y16 – Setting up ADB on OSX, Android app icons generation, catch key press with Angular & DIY french webserie

Set up adb on Mac OSX

adb ADB is the command line tool to manage your Android phone and so install and run apps or different ROMs for example. Setting up ADB on Mac OSX is not quite easy and I lost time to configure it, so the line below will help you if you have to set it.

echo 'export PATH=$PATH:/Users/[yourusername]/android-sdks/platform-tools/' >> ~/.bash_profile

Generate icons Android app

Link launcher_icon_generator Launcher icons for Android apps are requested to be in several formats, and you’ll spent a lot of time if you want to build them in all the sizes. Here, you can find a tool from Roman Nurik where you just have to upload your image in a good format (512×512 minimum I think), and it will generate it for you in all those formats:

  • xxxhdpi
  • xxhdpi
  • xhdpi
  • hdpi
  • mdpi
  • web
  • hi-res

In addition, you can add some effects like square, circle, vertical/horizontal rectangle etc. Try it!

Bring life to TextView

demo3 Yes, it’s possible and it’s very nice! Thanks to HTextView, you can add some animation effects to your TextView fields. You only have to add the lib dependency to your project:

compile 'hanks.xyz:htextview-library:0.1.5'

and add the element to your xml layout:

<com.hanks.htextview.HTextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="#000000"
    android:gravity="center"
    android:textColor="#FFFFFF"
    android:textSize="30sp"
    htext:animateType="anvil"
    htext:fontAsset="fonts/font-name.ttf" />

You can find HERE, the github repository to this project hosted by hanks-zyh. Star and share it to your network!

Catch key press with Angular

keypress_white If you want to provide some assistance using keyboard shortcuts in your web app (using Angular as front-end framework), I recommand to use a bower library called angular-keypress (you can find the Github repo HERE). Get it from bower:

bower install --save angular-keyboard-shortcuts

Use it simply like this:

<a ng-click="goToPreferences()" keyboard-shortcut="control+,">Preferences</a>
<a ng-click="openSettings()" keyboard-shortcut="s">Open Settings</a>

Very useful and enjoyable for users, really.

DIY French webserie

A short webserie (8 episodes) about DIY projects is proposed by Arte. It’s called “Fais-le toi-mΓͺme” and it’s about creativity and inventions by makers. If you are passionate by Arduino and RaspberryPi stuffs or simply curious about it, go to check it!

fais-le-toi-meme-720x330

All episodes are available HERE

W31Y16 – Twitter REST API, Speech recognition for your web app, Angular DOM loaded and nice web switch animation

Twitter REST API

One of the REST API that I very like simply because it’s well explained, with samples, etc. The official Twitter REST API. If you would like to use it on a web project using NodeJS, there’s the plugin you need, twit.

Before using the Twitter API, you need to follow some instructions for the app creation but it’s pretty simple… Here, I found a good tutorial or on the official documentation.

An example of use if you want to make a search about the word “android”

var Twit = require('twit');

var T = new Twit({
  consumer_key:         '...',
  consumer_secret:      '...',
  access_token:         '...',
  access_token_secret:  '...',
  timeout_ms:           60*1000,  // optional HTTP request timeout to apply to all requests.
});

T.get('search/tweets', { q: 'android', count: 100 }, function(err, data, response) {
  console.log(data);
});

Speech recognition

If you want to make your web app more interactive, just add the annyang library to your project! It allows you to call your actions with the voice instead of clicking buttons. For exmaple, if you have to control. Just test to the online demo. Import the lib and add your own commands is pretty simple… just take a look.

Import the lib

<script src="//cdnjs.cloudflare.com/ajax/libs/annyang/2.4.0/annyang.min.js"></script>

Implement your own commands

var commands = {
  'go to google': function() {
    redirect('http://google.com');
  }
};
annyang.addCommands(commands);
annyang.start();

You have some additional options like debug or language settings who could be very useful to see what is really captured and be more precise.

annyang.debug();
annyang.setLanguage('en');

Angular, DOM loaded ?

For some reasons, you need to know when your DOM is loaded to start actions, right? The easiest solution to do this with Angular is to add the code below in the controller of your view. As you can see, the controller will print in the console and the loader will be hidden.

// Execute after DOM loaded
angular.element(document).ready(function () {
    console.log('loading finished');
    $('#loading').hide();
});

Design of the week

I love this animation designed by Oleg Frolov. It would be nice to implement this to switch a night/light mode for an interface for example… The source code is available here, let me some minutes to add it in my own project! πŸ™‚

enable

And now, holidays:

  • Translate My Sheet update
  • DIY projects.