Aug 31, 2015

Install Docker under Ubuntu 14.04 (Trusty)

Docker supports Ubuntu versions:

  • Ubuntu Vivid 15.04 (64-bit)
  • Ubuntu Trusty 14.04 (LTS) (64-bit)
  • Ubuntu Precise 12.04 (LTS) (64-bit)
  • Ubuntu Raring 13.04 and Saucy 13.10 (64 bit) 

For both Vivid and Trusty you need nothing. It will work out of the box. Others will require some modifications. (Updating of some things, like kernel or installing with wget on 13.04)

1. To install docker from a repository do so:
sudo apt-get update
sudo apt-get install
sudo ln -sf /usr/bin/ /usr/local/bin/docker
sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/

2. Now run it with:
sudo apt-get install lxc-docker

3. Make it run on system boot:
sudo update-rc.d defaults

4. Ready to go! Run container with an Ubuntu:
sudo docker run -i -t ubuntu /bin/bash

To disconnect, or detach, from the shell without exiting use the escape sequence Ctrl-p + Ctrl-q

Aug 27, 2015

Remi and EPEL repositories in CentOS

There are 2 common repositories that come nowdays for centos. They contain tasty things, while they are absent in official repositories.

CentOS 5:
sudo rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

CentOS 6:
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

You can check you are successful like so:
ls -1 /etc/yum.repos.d/epel* /etc/yum.repos.d/remi.repo

Now you are only left to activate Remi repository:
sudo vi /etc/yum.repos.d/remi.repo

In [remi] section we need to change enabled=0 into enabled=1. It will look like so:
name=Les RPM de remi pour Enterprise Linux 6 - $basearch

Only need to update now:
yum update -y

Aug 25, 2015

Tmux quick start guide

Tmux is a handy terminal manager that allows you to switch between terminal sessions easily. Without losing history or windows upon ssh disconnects or similar. It is like screen, just better. (First of all because of using client-server based technology... )

Here is my minimal keyboard shortcuts guide that allows you to start using Tmux in a blink of an eye. Endless advanced commands and hotkey combinations you could always find by entering "man tmux" in a terminal.

Tmux is installed quite easily in most of common linux based systems. Just type:
$ sudo apt-get install tmux
$ sudo yum install tmux

This allows you to start using by starting it with
$ tmux a || tmux new
This command first tries to attach to existing running tmux instance and creates new in case it is not found.

Ctrl+b d - Will allow you to disconnect at any time. (This is also a way it is happening when you loose ssh session. How to connect - look earlier)

Each session can have many windows:
Ctrl+b c - Create a new window.
Ctrl+b 0...9 - switch to window #;
Ctrl+b p - switch to previous window;
Ctrl+b n - switch to next window;
Ctrl+b l - switch to next active window (to the one you have switched from to this window);
Ctrl+b & - close this window (Or just type exit in terminal.

One terminal can have multiple windows:
Ctrl+b % - splits current panel in part, vertically;
Ctrl+b " - splits current horizontally;
Ctrl+b →←↑↓ - switch between panels;
Ctrl+b x - close current panel (you could also type exit in a terminal window).

Minus is a scrolling behavior:
Ctrl+b PgUp - enters "copy mode", afterwards:
    PgUp, PgDown - scrolling;
    q - exit copy mode.

Good more complex gist of hotkeys also here:

Mar 5, 2015

Installing MySQL and phpMyAdmin for web development on a Mac OS X 10.9, 10.8, 10.7, 10.6

This is a simple guide on installing a must have SQL database engine for web development. It is often used at the beginning of the journey and I did not find a good guide for it. That made me make myself one and share with others. Hope somebody would benefit from it.

Jan 23, 2015

[Django CMS] Adding plugins inside plugins programatically

I have a task to migrate a website. Old one is plain HTML and new one is Django CMS. I have a script that parses an HTML page from old website in to CMS page and places it into proper place.
Task is to migrate all the page content (that is a CMS TextPlugin) into an interlinked pages setup. Like we have text

<p>blah blah </p><a href="/page/url">Text</a><p> some other text</p>

And I need to change it into CMS LinkPlugin that is nested inside of the TextPlugin. It have become a common standard in the Django CMS world now. Note we need to have a LinkPlugin because of the requirement to interlink pages.
E.g. <a href="/page/url"> is a link to CMS Page object.

The solution is divided into two major parts. First we need to have the link plugin added to a placeholder of the text plugin. It must also be nested by the TextPlugin, like Django CMS admin web UI would do.  So our plugin would look somehow like this in the CMS Page admin:
And the second is modifying the Text Plugin instance itself with placing Link plugin placeholders instead of <a></a> tags we have there.
In this particular example we have a placeholder named "content" and a page containing only one TextPlugin with text in it. We need to modify that text.
First we need to create an instance of a CMSPlugin that is attached to a proper placeholder and is nested in our TextPlugin instance. Creating a Link plugin (an instance of a configuration for that CMS plugin in practice) is a next step to achieve this.
That will be the part 2 of this article. Coming soon.

Jan 22, 2015

Don't put html, head and body tags automatically into beautifulsoup content

Was making a parser recently with BeautifulSoup. Came to the final with rendering contents of the edited text. Like so:
text = "<h1>Test text tag</h1>"
soup = BeautifulSoup(text, "html5")

text = soup.renderContents()
print text
It renders those contents with a result wrapped into the <html>, <head> and <body> tags. So print output looks like so:
'<html><head></head><body><h1>Test text tag</h1></body></html>'
That's a feature of the html5lib library, it fixes HTML that is lacking, such as adding back in missing required elements.

The workaround is simple enough:
text = soup.body.renderContents()
This solution will return an inside of the <html> tag <body>.
Result is:
text = '<h1>Test text tag</h1>'