понеделник, 15 август 2016 г.

Presentation about Babel

I will lead a presentation about Babel in Questers.
Babel is a in fact coverter from ECMAScript 6 to ECMAScript 5. If you want to use ES6 features you can use it into your code and after this you can transpile
it for production. Everione who is interested is welcome. The presentation will be conducted in the Bulgarian language. You can register here.

събота, 16 юли 2016 г.

How to have value like baseDirectory into singleton object in Sbt?


I am currently a lamer in sbt technology. Sbt stands for Simple build tool. This is a build system that is highly developed, modern and is the de facto standard build tool in the Scala world. Currently I'm using sbt for several job tasks and last week I came across a rather unpleasant problem that probably is very easy to solve for experienced Scala and sbt developer. I am writing this article to help people with a similar problem in the future. Sbt has several global settings. One of this global settings is
baseDirectory. Depending on the scope, this is the base directory for the build, the project, the configuration, or the task. You can easy get value of project base directory from sbt console. Just type
baseDirectory and you will get the value of this setting.
You can also use inspect baseDirectory and you will get additional information.
In sbt is a good practice to isolate long tasks into singleton object and keep build.sbt much shorter. This is very cool but in order to have some global settings into this singleton object there are several tricky things that you must to do. The same thing is true if you want to have streams available to the singleton object. My job task involved to process a certain way all the files that meet certain criteria. For this purpose, I had to have baseDirectory for project. When I tried to pass baseDirectory as a method argument in this way:
And this:
Every time I got error like this:
I tried several things. For example to pass baseDirectory.value in this way:
But I got errors that .value cannot be used in this way. In the end, I managed to solve the problem with using ".." into the singleton object, that means "the parent directory". But this solution is not good at all. What will happen if the location of .scala file is changed? I love stackoverflow. Sometimes you can ask and get valuable help and explanations. Also you can answer questions and thereby helping others. I asked the question and received a helpful guidance. So If you want to have baseDirectory or similar value into singleton object, you must define the object like this.
And into build.sbt this:
Or this:
I like second solution because looks much clearer.
You can also check example repository into github here. If you want you can check the stackoverflow question.

понеделник, 4 юли 2016 г.

Install latest maven 3 under Ubuntu.

Maven is the de facto standard build tool for Java. There is something that extremely annoys me under Ubuntu. That every time you need to install the latest maven 3 manually and never got it in the standard Personal Package Archives ('PPAs'). Of course there are external PPA, but always the question arises how much can be trusted their contributors. Today I again needed to update maven into one vagrant box so I repeat the exercise again. Maybe this bash script will be useful for the people with a similar problem in the future. The script just install the latest - 3.3.9 version of Maven. The idea is to can be modified easily in the future - just to change variables with name and path. I do not pretend that the script is good - I'm not bash programmer.

понеделник, 5 октомври 2015 г.

Jasmine Clock

Today I had to write unit tests for JavaScript time dependent code. I liked that Jasmine supported a way to make setTimeout or setInterval to behave synchronously. When we install clock with jasmine.clock().install(); into beforeEach we change behaviour of setTimeout and setInterval functions to be synchronous.
After this we can move forward in time like using time machine and check result of asynchronous process. We can go into future with jasmine.clock().tick function, which takes a number of milliseconds. This is small example code:

TimeoutSpec.js
1    describe("Jasmine Clock demo", function () { 
2     
3        // It is installed with a call to jasmine.clock().install  
4        // in a spec or suite that needs to manipulate time. 
5        beforeEach(function () { 
6            jasmine.clock().install(); 
7        }); 
8     
9        // Be sure to uninstall the clock after you are done  
10       // to restore the original functions. 
11       afterEach(function () { 
12           jasmine.clock().uninstall(); 
13       }); 
14    
15       it("setTimeout must behave synchronously", function () { 
16           var array = [1, 2, 3, 4, 5, 6]; 
17           var sum = 0; 
18           (function _handleArray() { 
19               sum += array.shift(); 
20               if (array.length != 0) { 
21                   setTimeout(_handleArray, 0); 
22               } 
23           }()); 
24    
25           // The cool part  
26           // We have something like 
27           // time machine and can  
28           // move time forward.  
29           jasmine.clock().tick(200); 
30           // 1 + 2 + 3 + 4 + 5 + 6 
31           // is equal to 21 
32           expect(sum).toEqual(21); 
33       }); 
34   }); 
35   
And here can be viewed this code: http://gonaumov.github.io/jasmineClockDemo/ running into Jasmine 2.3.4 with spec file.

четвъртък, 27 август 2015 г.

Get rid of crossdomain origin errors.

When developers work on web applications under Windows there are often crossdomain  origin errors. The old version of  Google Chrome browsers provides a  usefull feature
--disable-web-security command line argument for  chrome.exe but unfornatelly this option was deprecated.  When you try to use it under current version of Chrome
- Version 44.0.2403.157 m you will get the following error:
"You are using an unsupported command-line flag:   --disable-web-security. Stability and security will suffer.". I tried to download current Chromium build   but with no luck - this errors appear again. After a small time thinking I'm came to a solution that I want to share with other people with a similar problem. I download Opera that is based on Chrome. Under Opera this command line option
 works like a charm and you have the same tools available.  Even an emulator for mobile devices.


Here is small demo. Get response from yahoo when google is open. Executing of this small snippet
from console.

(function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
console.log(xhr.responseText);
}
}
xhr.open('GET', '//www.yahoo.com/', true);
xhr.send();
}());

And here is the result: 


But if you want to use just a Google Chrome I write this script to make the starting of Google Chrome browser without security much easier than it was before. The script checks if there is running instances of chrome.exe and if there is a present instance, alerts the user that the running instance must be killed before Google Crome is started. If the user clicks on Yes button, the script will kill all instances of chrome.exe. After this, will open a new browser instance without security. If the user clicks on No button, the script will do nothing. If there is no present running instance of chrome.exe, the script will start Google Chrome without security. How to use it? Just clone this repository and fill correct path to chrome.exe. The script is tested on windows 8 with admin rigths. Don't hesitate to write to me with suggestions and feature requests.
https://github.com/gonaumov/chromeRunner

събота, 13 юни 2015 г.

Cucumber-js and Chai how to expect if element with given selector exist in DOM

This week I had one problem with protractor and cucumberjs. I read protractor documentation and asked question into stackoverflow. I want to share one very small learned lesson here also. If you want to expect if element with a given selector exist in DOM you must use isPresent() it returns a promise that will resolve to whether the element is present on the page.

    element(by.id('someId')).isPresent().then(function(isElementVisible) {
         expect(isElementVisible).to.be.true;   
    });
 
Or use chai with promises.

    expect(element.isPresent()).to.eventually.be.false
 
However, the word "eventually" sounds unpleasant. We want to be sure not eventually sure. :)
Here can be viewed the quesion into stackoverflow.  

вторник, 2 юни 2015 г.

Емилиян Кърчев и http://energyaudit.bg

Емил или за възпитанието. Горкият Русо. Това е цитат от Богомил Райнов. Не е измислен от мен. Викнахме въпросният господин да направи експертиза на един теч, който излезе в следствие на направен ремонт. Решихме, че сайта му е най-представителен и изглежда най-професионално от всички. На сайта на господина няма цени. Казал е на жена ми цена от 138лв. Аз дойдох след работа, за да може да се извърши диагностиката, но не бях чул добре цената, която трябва да се плати.  Бях чул нещо от сорта на 174лв. Е дадох му 180лв с идеята, че ще си хване, колкото му трябват. Господина си ми пусна касова бележка за 180лв. След това разправял на жена ми, че за да ни пусне констативен протокол трябвало да чукне още 48лв а снимките се обработвали със специален софтуер. Не, че е кой знае какъв проблем де, но е важен принципа в крайна сметка. Браво Емо. Тия 50лв. да ги дадеш за лекарства. Ето го и сайта на господина.
Промяна от 04.06.2015г.
Да допълня. Това, че няма цени на сайта не отговаря на истината. Мое недоглеждане. Денят ми беше твърде зает, за да гледам сайта на господина. По тази причина и му дадох 180лв с идеята да си хване колкото е цената, както съм писал по-горе. Притежавам и касова бележка за сумата. По долу показвам и текущите цени на сайта на господина.
Сметката пак не излиза. При промяна цените спрямо тази дата (03.06.2015г) могат да бъдат извлечени от всеки кеш на търсеща машина.