Update Android Studio project – Gradle issues

Last year i worked to an Android Studio project, now i should make changes and reopened Android Studio after some months.
Obvious, there were a lot of updates and Gradle began to complain about the settings, recommending changes.
The best approach is to copy the current Gradle section in some text editor, delete the lines below compile ‘junit:junit:’, right clic on App node and choose “open Module Settings”

Here on Dependencies Tab clic the green “+” and add a library dependency

then search :

So are catched the right versions.

Categories: Android

Use Python 2.7 in Spyder

Installing the Python Development with Visual Studio 2017

is available Anaconda, a Python data science platform.
Inside Anaconda are installed some packages as Spyder, an useful IDE for Python that typically uses the latest Python (3.6).
But there are environments as Multichain where is requested Python 2.7.
In order to have Spyder working with Python 2.7 follow these steps:
launch the Anaconda command prompt, at the prompt type these 3 commands:

conda create -n spyder python=2.7 spyder
conda activate spyder

And Spyder is launched using Python 2.7

Categories: Multichain, Python

Problem with MacOS downloaded programs

I tried this morning to install Docker on MacOS (Sierra) , downloaded the .dmg file and double clicking on it, i got a message complaining that the app is damaged and can’t be opened.
And strange thing, the same with older .dmg that i was installing without problems: could be an recent update.
After some search i found this page and effectively trying

sudo spctl --master-disable

i can open the .dmg and install Docker.

Categories: Docker, OSX

Differences in browsers engines under AngularJS

Working to updates on a AngularJS site, i discovered subtle differences.
I don’t know if there were these problems before, but certainly they raised while testing with Angular 1.6.5
First, if the user was switching the site language from English to Italian while working , saving a date Moment was not able to parse the date giving “Invalid date” using the latest Chrome and Firefox, while with Ie11 and Edge all ok.
In origin the code was (oh yeah, it uses the DOM objects instead of the binding..)

var testDate = moment($("#txtBirthDate").val()).format($scope.DateFormat.toUpperCase());
if (testDate === "Invalid date") {
    logWarning(localize.localizeText("DateNotValid"), null, true);
    return false;

For the first thing , using Visual Studio 2017 and starting the project i noticed that finally the breakpoints in javascript code are working also under Chrome, great thing:

Obvious , $scope.DateFormat.toUpperCase() is evaluated at runtime as YYYY-MM-DD for English and DD/MM/YYYY for Italian.
In order to work also with Chrome and Firefox this is the correct Moment syntax:

var testDate = moment($("#txtBirthDate").val(), $scope.DateFormat.toUpperCase()).format($scope.DateFormat.toUpperCase());

This code instead works without changes in all browsers:

var datBirthDate = moment($("#txtBirthDate").val(), $scope.DateFormat.toUpperCase()).toDate();
var BirthDate = datBirthDate.yyyymmdd();  // as requested for SQL Server

Then the other issue, an awkward issue.
The customers have the bad habit to press F5 or worse the browser refresh button in the pages, that in Angular does little sense.
In the site the other controllers (the ones not relatives to the home page) are loaded with ocLazyLoad (current version v1.0.10), in config.route.js the code was

}, {
    url: '/phones',
    config: {
        title: 'Phones',
        role: 'Administrator;PowerUser;User',
        templateUrl: 'app/tabelle/phones.html', 
        resolve: requireDependencies(['app/services/datacontextphones.js'], ['app/tabelle/phones.js']]),
        settings: {
            content: '<i class="fa fa-mobile"></i> {placeholder}',
            nav: 3,
            localizeKey: 'mnuPhones',
            minicontent: '<i class="fa fa-mobile" title="{placeholder}"></i>'
}, {

The function:

function requireDependencies(depContext, depMain) {
    return {
        resolvedData: ['$q', '$rootScope', '$ocLazyLoad', function ($q, $rootScope, $ocLazyLoad) {

and this code with Ie11 and Edge was working fine, the users could hit F5, the browser refresh button, and the page is refreshed without problems.
Instead with Chrome and Firefox:

After some struggle, the working code in config.route.is that doesn’t use the function requireDependencies and all pages are surviving to the refresh in all browsers:

}, {
    url: '/phones',
    config: {
        title: 'Phones',
        role: 'Administrator;PowerUser;User',
        templateUrl: 'app/tabelle/phones.html', 
        resolve: {
            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                return $ocLazyLoad.load({
                    name: "phones",
                    files: [
        settings: {
            content: '<i class="fa fa-mobile"></i> {placeholder}',
            nav: 3,
            localizeKey: 'mnuPhones',
            minicontent: '<i class="fa fa-mobile" title="{placeholder}"></i>'
}, {

Categories: .NET, Angular, Javascript, Vs2017

Dockerize .NET Core 2 Web App

Recently Microsoft officially announced .NET Core 2.
Installing the SDK in Visual Studio 2017 is available the creation of .NET Core 2 projects.
I tried to create a Docker solution with the new kid on the block.
Currently it seems that with Yeoman there are still no support for .NET Core 2, the available templates at the moment are only for .NET Core 1:

So i tried to create first the project with Visual Studio 2017:

I created a new Core Web App MVC named aspnetapp,

without enabling the native Microsoft support for Docker; launching the Web App it worked without issues:

Then i added a Dockerfile in the project root with this content, following the official page:

FROM microsoft/aspnetcore-build:2.0 AS build-env

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

And a .dockerfile in order to make the build context as small as possible


at this point from command prompt in the directory where is Dockerfile

docker build -t aspnetapp .

and then with

docker run -d -p 8080:80 --name myapp aspnetapp

the site this time runs from the container:

and we have the new image:

D:\work\MyDotNetCoreApp\aspnetapp>docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
aspnetapp                     latest              a7ed19cfc58e        8 hours ago         283MB

Categories: .NET Core, Docker, Vs2017

SSH and X Windows with OSX

In the previous post i wrote about Ubuntu and SSH/X Windows.
Having a Mac Mini without keyboard (i access only via VNCViewer) and problems as “where is that damned @ symbol??…” i tried to work via SSH and X Windows, from the other hand OSX is a Unix system.
For the first thing it must be installed XQuartz, because from Sierra version OSX has no more an native X System.
SSH must be configured in System Preferences->Sharing

Here clic for activate Remote Login,

OSX advice how to connect:

In order to work SSH and X, open with nano or vi the file (make a sudo su, before) /etc/ssh/sshd_config
Here uncomment (delete the initial # character) the lines

X11Forwarding yes
X11DisplayOffset 10

At the end of the file add, if not already present (XQuartz should add this line)

XAuthLocation /opt/X11/bin/xauth

and save.
A reboot is better, anyway with

sudo launchctl unload  /System/Library/LaunchDaemons/ssh.plist

the ssh service is stopped, with

sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

ssh is started.
So also from Mac we can launch locally the old friend Xeyes:

Putty must be configured as done for Ubuntu.

Categories: OSX

X terminal with Windows 10 and Ubuntu 17

30 years ago i was more an sysadmin than a programmer and i was configuring X Terminals on HP-UX and AIX for CAD systems.
I still remember the HP Turbo SRX, a graphic accelerator for the HP9000 series big as a bedside table (and very heavy..) and the AIX strange problem about network interrupts, killed under heavy processor load so the X terminals were killed.
And the HP demo of the bee walking inside the monitor glass? how many memories…
Now, after many years, i needed to launch on a Windows 10 instance Linux apps with a graphical interface.
After the traditional search on Google, I found a viable solution.
For the first thing it is requested to install the OpenSSH server:

sudo apt-get install openssh-server

Then make a copy on your local folder of the configuration file:

sudo cp /etc/ssh/sshd_config ~

Change with vi (if vi is awkward, also Nano is ok) the config file:

sudo vi /etc/ssh/sshd_config

By default the port is 22, could be useful change this value (In my case i left Port 22 because is only a test instance.); also set

PermitRootLogin no

to avoid logins as root, could be very dangerous.
Very important to uncomment (the comment is the # char)

X11Forwarding yes
X11DisplayOffset 10

Then configure specific users allowed to login: this can be tricky, because when you make login in a Ubuntu instance tipically is used an alias , the true user name is the one in the first column when you type cat /etc/passwd.
For example in my Ubuntu instance i see

But the real user name , as i can see in /etc/passwd, is “alessi”.
So in my case at the end of sshd_config i placed

AllowUsers alessi

Other users can be listed with a space between names.
At this point :

sudo /etc/init.d/ssh restart

And the Ubuntu part is done.
For the Windows part, the first software requested is a Putty client and i used this: simple and working.
With this you can do a remote SSH and you work without problems with the character shell:

Here you can use vi, nano, bash commands.
But if you try to launch for example gedit , the Ubuntu counterpart of Windows Notepad, you get:

In order to show an X Terminal window, you need a local Xserver.
There are many solution, i use Xming.
The use is very simple, install with defaults and launch Xming.
The other program XLaunch is a wizard where you can configure how to see the windows:

XMing server icon is then placed on the Windows toolbar:

Now we set Putty.
Verify that in Connection/Data there is:

Then in X11 part:

That is it must be enabled the X11 forwarding and must be set the “X display location” as “localhost:0”.
So entering the gedit command we can see the X Window:

One problem that can arise is: ok now i want to launch the MySQL Workbench which is installed on Ubuntu, but which is the shell command? an icon on Ubuntu has no properties as in Windows.
I discovered this article, answer “just for fun”, so saving the extended version (with the description) for example as programs.py launching

python programs.py

You see the installed programs (the ones with a graphic interface) and with a click the program is launched.
Is not the same as displaying the Ubuntu desktop (i searched, but it seems a problem) anyway is working; but not all programs can run, for example Files and Visual Studio Code on Ubuntu.
Anyway there is a problem: you can launch programs as normal user (when there is the $ prompt, in practice) but if you try sudo su and then at the # prompt you try for example xclock (or the old, nostalgic xeyes..) you have an error:

root@dockerserver:/home/alessi/web# xclock
PuTTY X11 proxy: Unsupported authorisation protocol
Error: Can't open display: localhost:10.0

Fortunately this can be fixed: back as normal user ($ prompt) and given your username for example the mine, alessi, launch this command:

xauth add $(xauth -f ~alessi/.Xauthority list|tail -1)

Launch sudo su, and as root the XWindows programs e.g. xclock are working.

Categories: Python, Ubuntu, VmWare

Dump a .NET DataTable in VB.NET as XML file

If we have a DataTable named rstData in our VB.NET code:

Dim ds As New DataSet
ds.Tables(0).TableName = "ATableNameYouWant"

Categories: .NET, VB.NET

TeamViewer in Ubuntu 17.04

In theory Ubuntu should have by default the connection via Vnc, but after some struggle having no time i switched to TeamViewer.
But even in this case, the things are not easy.
Using the above link, it is downloaded a file named (the current version) teamviewer_12.0.76279_i386.deb.
By right clicking this file in the Ubuntu file manager is proposed the installation (“Open with software install”), you see a window with an button “install” that does nothing.
After some struggle i found that must the installed the package gdebi with (as root with “sudo su”, obvious)

apt-get install gdebi

In my case i got some errors about “unmet dependencies”,with the advice to run

apt --fix-broken install

Done this, with apt-get install gdebi was installed.
At this point by running

gdebi teamviewer_12.0.76279_i386.deb

finally TeamViewer was installed and it runs.

Categories: Ubuntu