Search This Blog

Tuesday, October 29, 2013

Python cheat sheet

  • How to pretty print JSON record
echo '{"name":"value"}' | python -mjson.tool

Sunday, October 27, 2013

Home directory and dotfiles management

In Linux you can customize your environment by creating custom aliases and various scripts. After some time this flexibility becomes difficult to managed if you work on many different machines. And if some of the hosts are cloud servers that are being deleted and recreated setting up your home directory can become a boring and annoying task.


How to customize and maintain your home directory config files on many servers.

  1. Create a repository for your configs on github. You can track your config files in a repository like mine: dotfiles on github. There are many existing repositories that that you can clone or simply reuse.
  2. On the server/cloud server install This bash script will help us to maintain the config files.
  3. Download your dotfiles (config files) repository on the server
  4. Install it in your home directory
  5. Add the customization to .bashrc file


Tuesday, October 8, 2013

How to dynamically inspect and manipulate the content of your loaded page inside chrome browser

The next generation browsers, like Google Chrome, can offer an powerful feature (Chrome DevTools) that allows you to inspect, debug and manipulate any web page element that you browse.

Demonstration and results description
  • Open any web page in your browser
  • Open the Chrome DevTools console tab: Ctrl+Shift+J 
  • In the console type the following code and press Enter
document.body.innerHTML="this is now your new page"
"this is now your new page"
  • Your loaded page within the browser window should be replaced now with our custom string
  • By running different JavaScript code you can change the behavior and content of your page
Now to start exploring this all what you need to know is basic JavaScript knowledge and some understanding of the HTML standard (a good reference can be found here HTML - Living Standard).


Thursday, October 3, 2013

Beautiful code formatter for JavaScript in Sublime

I needed recently to work with some JavaScript code to understand how bookmarklets work in Google Chrome. Unfortunately the js code was often not well formatted and difficult to read.


How to automatically reformat JavaScript code so it looks beautiful and is easy to read.


I recommend this online site if you don't need to have this functionality in your editor of choice: To enable beautiful code formatting in Sublime you can:

To test that the node.js and the necessary plugin is installed correctly you can run the node virtual machine and try to import the module:
$ node
> require("js-beautify")
{ [Function]
  js: [Function: js_beautify],
  css: [Function: css_beautify],
  html: [Function],
  js_beautify: [Function: js_beautify],
  css_beautify: [Function: css_beautify],
  html_beautify: [Function] }

To test that the plugin is installed successfully in in sublime you can:
  • check sublime tree directory
     ... Sublime2\Data\Packages\CodeFormatter\
To trigger the formatting:
  • Menu tools -> Command Palette (Cmd+Shift+P or Ctrl+Shift+P) and type `Format`.
  • The default keyboard shortcat is  ["ctrl+alt+f"] or 
  • If you want to run the command from the console

For further info about node.js and the JavaScript virtual machine functionality

Tuesday, October 1, 2013

Sublime macro error

Macros are a very power full tools when working with text editors. If you repeatedly typing the same commands/characters to edit your text you can always try to capture them and save as a macro.


A macro that tries to capture the ALT+F3 keyboard shortcat to highly all the word occurrence in text (more about this here) doesn't work and is erroring out on the console with this message.
Unknown macro command find_all_under


You can reproduce this by trying these steps:
  • Create a new file with this content.
    Line : aaa
    Line : bbb

  • Select menu tools -> record macro in sublime.
  • Highlight the ":" char and press ALT-F3 to mark two lines.
  • Stop macro and save it.
The file should look similar to this one:
   "by": "characters",
   "extend": true,
   "forward": true
  "command": "move"
  "args": null,
  "command": "find_all_under"

When you try to execute this macro it doesn't work and you can see the error message in the console window.

Analysis and solution

The command find_all_under is documented and works fine. You can always try to run it manually from the console yourself.

To create the automatic solution and let the editor to do the work for me I decided to write a Plugin using Sublime Python API. The code works perfectly fine and can be found on my github account: under the file All what you need to do is to install this plugin and execute it manually or use a keyboard shortcat to trigger it.

Workaround example:


Sublime Python API