CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

Tag Archives: node.js

MagicMirror2 and Chuvash

This post is about my setup of the popular MagicMirror2 application. I show the steps needed to set it up on a Raspberry Pi Zero W and connect it to a TV set. As a bonus, I share my thoughts on the Chuvash localization work.

MagicMirror2 is a DIY project and an open-source application, voted to number one of the best Raspberry Pi Projects. In essence, it shows information of your choice (weather, calendar, news) on a screen that is embedded in a mirror.

I was introduced to MagicMirror2 by my colleague, who uses it in another way: rather than having it in a mirror, he has it on his smart tv. The customisability is the beauty of the whole DIY and the Raspberry Pi.

Installation

I also decided to use it on my tv, through the built-in web browser. My raspberry pi zero w required some special steps due to its processor architecture. Fortunately, I found a guide for MagicMirror2 and Raspberry Pi Zero W which I used as a starting point.

After trying it, I found that I needed those steps for my server-only magic:

  • Install node and npm for armv6l
  • Clone the MagicMirror
  • Install npm packages targeting the armv7l
  • Run the server
# node from apt won't work
wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-armv6l.tar.xz
tar xvf node-v10.16.0-linux-armv6l.tar.xz
cd node-v10.16.0-linux-armv6l/
sudo cp -R * /usr/local/
sudo reboot
git clone https://github.com/MichMich/MagicMirror
cd MagicMirror
# it needs to be armv7l, not armv6l
npm install -arch=armv7l
# if errors arise: rm -rf nod_modules. Then npm install again
npm run server .
view raw magicmirror.sh hosted with ❤ by GitHub
Creating a bookmark on the TV browser.

My tv screen with MagicMirror2 localized into Chuvash

Chuvash

Every time I work with software I try to think: can I help to translate/localize it to Chuvash. Chuvash is a “little” language, it is only spoken by 1.5 million people. Almost in all cases, it is hard to even to register the Chuvash as such (like in Windows, or macOS), and it is even harder to localize applications, because they tend to have thousands or sometimes millions of strings to translate (and maintain!).

With MagicMirror I experienced how work from the past can help today, how small pieces can become connected parts of a bigger picture.

MagicMirror uses momentjs, a javascript library for datetime. In matter of fact, that’s exactly something that I already have worked on:

That was nice! I changed language to “cv” in the config/config.js and the most of the interface turned into Chuvash. (cv – is the iso code for Chuvash language). What a feeling of joy!

Why that excitement? Well, almost everything in the Chuvash IT (UX, localization, keyboard layouts, speech recognition, machine translation etc) is driven and sponsored by volunteers and a community. That’s why it is a special joy to see pieces come together, even though it is a small DIY project.

The MagicMirror2 itself does a minimal set of strings to translate. I translated it and submitted a Pull Request, which has been already merged to the develop branch.

I also created a list of Compliments in Chuvash and submitted it as a Pull Request.

nodeunit and SharePoint: unit tests in javascript

nodeunit is a (relatively) new test framework for javascript, mainly for node, but it can be run in a browser as well. The most popular framework for testing javascript is Qunit, but I’ll lab with it another time. I found nodeunit tests in moment.js – the best date handling framework for javascript and it worked very well.

So first of all, why should we test? The best answer is actually: Life is to short for manual testing (it was actually the slogan at the Google London Test Automation Conference 2007.

Why nodeunit?

Nodeunit can be run directly on server, it can test your javascript models. Even SharePoint related stuff can be tested outside the web browser. You can even automate your javascript unit tests before you build or deploy.

Nodeunit basics

We create a very simple javascript file in a sharepoint solution: CustomerModel:

Note the last if statement. This just defines what to export in nodejs.

To be able to run nodeunit tests on server we have to install node.js. Then we have to install nodeunit with npm globally:

npm install nodeunit -g

Then create a test file: TestCustomerModel.js:

Btw, here is my solution:

Next, run the test:

nodeunit TestCustomerModel.js

Allright, something is wrong:

Aha, we forgot the space. Let’s fix it:

And the test result is much better 😀

Nodeunit in web browser

nodeunit can be run in a web browser as well. I’ll test the same CustomerModel in this lab. Very simple stuff so far 😀

We create an application page, called Test.aspx. Download “nodeunit.js“. If you load javascript files in your master page and the tests are dependent of them, make sure you have the same master page in your application page:

Create browser/TestCustomerModel.js:

Change the Test.aspx:

When you deploy this as an aspx page, you’ll not see the test results, because nodeunit writes directly to body element, which is not rendered… We have to change nodeunit.js a little bit..

Then we can see the result on the page:

The whole solution for this lab can be found in my repo on github.

Hello world in node.js

I know, node.js has been present for a while. But I actually had no time to try it. I was surprised that now it is very straight forward to start with node.js. Allright, everything begins with Hello world. Eventhough it is available for allmost all combinations of operating systems and servers, the easiest way to test it was actually Ubuntu. To install just run:

sudo apt-get install nodejs

Then make a new directory and create the hello.js:

mkdir hello
cd hello
vi hello.js

The javascript code creates a server, instructs what to send back as a response and says to node to listen to port 40113 (what a weird number 🙂 )

var http = require('http');
http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8' });
  res.end('Salam tĕnce!');
}).listen(40113);

After that, just start the node process:

node hello.js

Very simple. Now go to localhost:40113 and see the result!

node.js on c9.io (Cloud9 IDE)

Even simpler way to try node.js is to create an app in Cloud9 IDE. Begin with a hello-world app.

That’s it.

Now some other useful links for starting with node.js:

Update:

If you want to get the latest node package, you shouldn’t install nodejs from apt. Just clone the node git repo, compile and update the PATH. npm package is preinstalled then:

git clone git:github.com/joyent/node.git
cd node
./configure
make
sudo make install
export PATH=${PATH}:/usr/local/bin

Or add a new repository to get the latest stable version of node.js

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
node.js and SharePoint

Luc Stakenborg has developed a node.js package for retrieving data from SharePoint. To use it, install two packages:

npm install xml2js
npm install sharepoint

Then create a js file with this content:

var SP = require('sharepoint'),
    site = 'http://yourdomain.sharepoint.com/teamsite',
    username = 'yourusername',
    password = 'yourpassword';

var client = new SP.RestService(site),
    posts = client.list('Posts');

var showResponse = function (err, data) {
    console.log(data);	
}

client.signin(username, password, function () {
    posts.get(showResponse)
});

javascript console in Powershell

It can’t be easier. If node is installed, just fire up PowerShell and type node:

Daniel Chronlund Cloud Tech Blog

News, tips and thoughts for Microsoft cloud fans

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Architect, Speaker, Author

Microsoft 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Mai Omar Desouki

PFE @ Microsoft

Cameron Dwyer

Office 365, SharePoint, Azure, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

DevOps, Cloud and Blockchain Consultant

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

blksthl

Mostly what I know and share about...