Monday, March 23, 2015

fedora: How to find out which package provides a specific file

If you need to find out, for example, which package in fedora provides htpasswd command, you may do it with the command:
yum provides \*bin/htpasswd


How to set up authentication for your website with nginx

You can set up basic authentication with nginx to restrict access to your website:

Install httpd-tools package first:
sudo yum install httpd-tools

If you are on Ubuntu install that package:
sudo apt-get install apache2-utils

Add to your nginx config:
server {
...
auth_basic "closed site";
auth_basic_user_file conf/htpasswd;
}

Go to /etc/nginx and create folder conf:
cd /etc/nginx
sudo mkdir conf

Then you need to generate file htpasswd that contains authentication data:
sudo htpasswd -c htpasswd admin

Sunday, March 22, 2015

byobu: Vertical window split issue

Vertical split with default keys configuration in byobu (which is Shift+F2) doesn't work. I decided to change it to Ctrl+F1 instead. To do it open keybinding file:
sudo vim /usr/share/byobu/keybindings/f-keys.tmux

And replace line
bind-key -n S-F2 display-panes \; split-window -v

with
bind-key -n C-F1 display-panes \; split-window -v

Make sure that tmux keybinding is active and default one. Open file
/usr/share/byobu/keybindings/f-keys

and check that it contains
source $BYOBU_PREFIX/share/byobu/keybindings/f-keys.tmux

How to download tracks from deezer

There is a nice service deezer.link which allows you to download tracks from deezer. All you need to do is to copy and past unique link of the track from deezer. It would be good to automate that process for albums and playlists.

adeezer project was created exactly for that purpose. It is cross platform and is known to work on Windows and Linux (should also work fine on OSX).

Download and extract the latest version from here or clone the repository with command:
git clone https://github.com/e-shulitsky/adeezer.git


The recommended way of using adeezer is with virtualenv, but you can just install all dependencies and start using it:
pip install -r requirements.txt




Some examples of using the script:
  • Download the playlist with id 101
    python adeezer.py -p 101


  • Download the album with id 321
    python adeezer.py -a 321


  • Download all your favourite tracks
    python adeezer.py -f 1000

    Where 1000 is your deezer id. You can also use your username or email instead of id.




  • All tracks are downloaded in your <home_directory>/Downloads/<item_id>. To populate ID3 tags of downloaded tracks use that command:
    python add_tags.py <path_to_folder> "<album_name>"


    Windows users might have some problems with quick start, because python and pip is not installed in their system by default. Here is quick start guide for them:

    1. Download and install ActivePython 2.7 from http://www.activestate.com/activepython/downloads


    2. Download and extract adeezer from https://github.com/e-shulitsky/adeezer/archive/master.zip


    3. Install dependencies. Run from commmand prompt:

    pypm install mutagen progressbar2 requests selenium wsgiref


    4. In Command prompt go to the directory with adeezer.py and use any command from that article to download tracks


    How to create git commit template

    At work we integrated git with JIRA. If commit starts with our project name in JIRA and contains issue id, it will be automatically linked to that issue. For example:

    PROJECT-10 Fix timezone

    That pattern requires that every commit starts with the same characters "PROJECT-". Git supports commit templates, so every new commit message will include text from this template.

    To make it work you just need to create a simple text file and configure git to use this file:
    git config --local commit.template /path/to/git-commit-template.txt

    How to find outdated python packages in your environment

    The easiest way to find out if updated version of any installed package is available is to run that command:
    pip list --outdated


    There is also a special package for that task which is called pip-tools

    Tuesday, December 9, 2014

    bash: Colourful side-by-side command line diff

    I have never liked default linux diff command. The more changes you make, the less informative it becomes. When you work with git it would be nice to have side-by-side comparison of original file and a new file with changes. Graphical tools like smartgit and meld do it really impressive.

    But sometimes it is more comfortable to use command line tools. For colourful side-by-side git diff you can use cdiff. The simpliest way to install it is with pip package manager:
    pip install cdiff

    Then in your repository run:
    cdiff -s

    And the result is gorgeous!

    The next tool is called icdiff. It does basicly the same, but with files. Install it with that command:
    curl -s https://raw.githubusercontent.com/jeffkaufman/icdiff/release-1.2.0/icdiff \
    | sudo tee /usr/local/bin/icdiff > /dev/null \
    && sudo chmod ugo+rx /usr/local/bin/icdiff


    Use it like this:
    icdiff file1 file2