Articles

Right to left implementation tricks

Introduction

At some point you may want to have bidirectional (RTL) support in your application / web site. That means you want to have a support for Arabic, Hebrew and other right-to-left languages. Before everything let me quote from W3C some of the definitions:

  • Bidirectional text – in languages that use right-to-left scripts any embedded text from a left-to-right script and all numbers progress visually left-to-right within the right-to-left visual flow of the text. (Of course, English text on this page could also contain bidirectio[……]

Read more about post Right to left implementation tricks

Fix SSL problem when using Ruby “gem install”

During work with GruntJS task named Saas I got stuck on using gem command (the gem command allows you to interact with RubyGems). The problem was with SSL certificate. So, how to fix SSL problem when using Ruby “gem install”? Replace the ssl gem source with non-ssl as a temporary solution:

gem sources -r https://rubygems.org/
gem sources -a http://rubygems.org/

PhantomJS and source code instead of page

Running the code in PhantomJS might bring source code instead of page (the screenshot from that is generated using page.render);

output_utf8_with_bom

The reason of that is because the file has encoding UTF-8 with BOM. You’ll need to convert encoding to UTF-8 without BOM. After that the page is rendered properly.

output_utf8_without_bom

PhantomJS, resources and relative path

PhantomJS (at least version 1.9.8) is not loading resources when you want to use relative path. However, after some research and experimenting here what’s working for me. Example:

var page = require('webpage').create(),
    content = '',
    relativeScriptPath = require('system').args[0],
    fs = require('fs'),
    absoluteScriptPath = fs.absolute(relativeScriptPath),
    absoluteScriptDir = absoluteScriptPath.substring(0, absoluteScriptPath.lastIndexOf('/'));

console.log('scriptDir: ' + absoluteScriptDir);

content += '';
conten[......]

Read more about post PhantomJS, resources and relative path

How do I upgrade npm itself from 1.4.28 version to 2.1.14 on Windows 7?

After some struggling with upgrading npm itself from version 1.4.8 to 2.1.14 I ended up with following solution:

  • I have installed NodeJS, newest version (just overwritten current installation)
  • The npm was installed in (1) C:\Program Files\nodejs\node_modules\npm
  • I have installed new version of npm: npm install npm -g the new version has been located in (2) %USERPROFILE%\AppData\Roaming\npm\node_modules\npm

Now, all you need is to delete all files in directory (1) and copy all files from directory (2) to (1).

npm 2.1.14

How do I set my default Git editor in Windows to create and edit your commit and tag messages

By default, Git uses whatever you’ve set as your default text editor or else falls back to the Vi editor to create and edit your commit and tag messages. To change that default to something else, you can use the core.editor setting. Example for setting default Git editor in Windows to Notepad++:

git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Note: use above as a one line command.

How do I valid my code on Windows before I commit to Git repository?

Introduction

Like many other version control systems, Git has a way to execute custom scripts when certain important actions occur. One of the good thing to do is to automatically valid the code before you commit it to repository. Even, if you are doing it manually frequently you may forget to do that just before commit and this means that you’ll send invalid code. For example you may run just your unit test and forget to run unit tests for whole project. To prevent from it we can use Git pre-commit hook. What this does:

The pre-commit ho[……]

Read more about post How do I valid my code on Windows before I commit to Git repository?

TIP: Loading performance testing, console and cache

When you start measuring performance of downloading files by the browser then don’t forget to check if you have a turned on your cache. For example, you may have open browser developer tools and due of that the cache may be turned off (because you checked it in the settings long time ago and forgot about that). This means that the files are always downloaded and you may think that files are never cached.

Events – why something.changed instead of something.on(“changed”, ….

Whenever I was using custom events there were:

something.on("changed", function myonchange() {
    do_something_here
});

However, now I start to use better way:

something.changed(function myonchange() {
    do_something_here
});

The benefits of this change are:

  • The list of events can be seen in the debugger.
  • Events can be copied from one object to another.
  • Several events can be aggregated into one.