search

Monday, December 14, 2015

fedora: Disable Komodo Edit file association

Remove
text/plain=komodo-edit-9.desktop
from file
~/.local/share/applications/defaults.list

Thursday, December 10, 2015

bash: How to clean logs

One of the fastest and easiest ways is just like this:
> /var/log/syslog

bash: How to remove all *.pyc files

Remove all *.pyc files from the current directory (and subdirectories):
find . -name \*.pyc -delete

Sunday, November 15, 2015

firefox: Enable tracking protection for normal session

Firefox 42 includes very interesting feature - Tracking protection. By default it is active only in the Private mode. When the Firefox team presented a new video that described the usage of the Memory tab in the Developer toolbar, they show that the CNN website normally consumes about 40 Mb of memory and with Tracking protection on it consumes about 10 Mb. If you want to enable this feature not only for the private sessions, but also for the normal sessions, you can do that by typing about:config in the address bar and changing the value of the privacy.trackingprotection.enabled to true: There is also a really interesting setting privacy.trackingprotection.updateURL, which means, that, I believe, you can host your own tracking protection list (See shavar project, blocking list format is here). When Tracking protection has blocked some resources, it shows a shield icon near the address bar. If you open the Developer console (F12 or Ctrl+Shift+K) you can see what resources were blocked: Together with AdBlock extension it could be a nice way to improve your browsing expierence.

Change colours in byobu

Colour settings file for the byobu located in the folder ~/.byoubu, if you use tmux, it will be color.tmux:
BYOBU_DARK=black
BYOBU_LIGHT=white
BYOBU_ACCENT=cyan
BYOBU_HIGHLIGHT=cyan
MONOCHROME=white
BYOBU_ACCENT - is the colour of the window delimiter; BYOBU_HIGHLIGHT - is the colour of the current highlighted window; MONOCHROME - background colour of the window title in the bottom panel;

fedora: Automatically start application during the boot

To start an application automatically in fedora, you need to create a *.desktop file in the directory ~/.config/autostart, for example:
gedit ~/.config/autostart/flux.desktop
The content of the file can be something like:
[Desktop Entry]
Type=Application
Name=flux
Comment=xflux
Exec=/home/jsn/app/xflux -l 52.3837151 -g 4.8806328
Terminal=false

Tuesday, November 10, 2015

fedora: How to add user to sudoers

You can add user to the sudoers with command:
usermod username -a -G wheel
Log out is required.

Wednesday, October 7, 2015

How to open browser (Chrome, Firefox) on the remote machine via terminal

You can open a chrome window on the remote machine via terminal with X11 forwarding. First of all, some configuration needs to be done. Open on your machine (client) ssh configuration:
vim ~/.ssh/config
Make sure that it contains:
Host *
  ForwardX11 yes
Check that on the server (remote machine) X11 forwarding is enabled. Open this file:
vim /etc/ssh/sshd_config
and check that it contains:
X11Forwarding yes
X11DisplayOffset 10
Now you can connect from your machine to the remote server with command:
ssh -Y your_name@server
Check with (env command) that environmental variable DISPLAY is something like localhost:10.0. If not, set it with command:
export DISPLAY=localhost:10.0
To check that everything was set up correctly, run on the remote server:
xclock
You should be able to see a window of the xclock application. Now you are ready to run chrome with command:
google-chrome
I had some permission issue that prevented chrome from starting, I managed to fix it by changing user data directory:
google-chrome --user-data-dir=.chrome_profile
This also might be useful:
google-chrome --no-sandbox 
Firefox can be launched just with:
firefox 
Make sure that you have permissions for the .mozilla and .cache directory on the remote machine

git: How to change the author of the commit

If you want to change the author of the specific commit (for example the latest one), run rebase command:
git rebase -i HEAD~1
HEAD~1 points to the latest commit, but it can be a commit id or branch name. To mark a commit for edit, replace `pick` with `e`: Replace commit author:
git commit --amend --author "Your Name <your.name@mail.com>" 
Finish rebase:
git rebase --continue

Tuesday, September 15, 2015

How to unset environmental variable

For example, you set DJANGO=true environmental variable with command:
export DJANGO=true
To unset it run this command:
unset DJANGO

Sunday, September 13, 2015

How to display all available package versions in Ubuntu

To display all available package versions use next command:
apt-cache madison
For example:
vagrant@vagrant:~$ apt-cache madison redis-server
redis-server | 2:3.0.2-3~bpo8+1 | http://http.debian.net/debian/ jessie-backports/main amd64 Packages
redis-server | 2:2.8.17-1+deb8u1 | http://security.debian.org/ jessie/updates/main amd64 Packages
redis-server | 2:2.8.17-1 | http://http.debian.net/debian/ jessie/main amd64 Packages
     redis | 2:2.8.17-1 | http://http.debian.net/debian/ jessie/main Sources
     redis | 2:2.8.17-1+deb8u1 | http://security.debian.org/ jessie/updates/main Sources

Friday, May 22, 2015

How to configure dnsmasq to forward all requests to specific address

For example you have a virtual machine, which you use for local development, and you want all requests to the sitesupport.net (name of the website that you are developing) forwarded to the virtual machine. We will use dnsmasq to achieve it.

Install dnsmasq:
sudo yum install dnsmasq


Start it with command:
sudo service dnsmasq start


Check if it was started without any errors:
sudo service dnsmasq status


If there is an error that dnsmasq failed to start because port 53 is already in use, you can check what process listening this post with command:
sudo netstat -tulpn | grep :53


If the process is dnsmasq itself it probably means that you have libvirt installed that has its own dnsmasq copy. To resolve that conflict we need to configure dnsmasq. Configuration file we are going to store in /etc/dnsmasq.d/vm.conf. By default dnsmasq uses file /etc/dnsmasq.conf for configuration. If you open that file, you will be able to see lots of examples and configuration descriptions. Lets left this file intact (almost) and allow dnsmasq to extent configuration with files from dnsmasq.d directory by adding (uncommenting) line:
# Include all files in a directory which end in .conf
conf-dir=/etc/dnsmasq.d/,*.conf


Now create file /etc/dnsmasq.d/vm.conf with the following content:
interface=lo
bind-interfaces
address=/sitesupport.net/192.168.33.10


The first line determines what interface dnsmasq will be listening. To check all available interfaces use command ifconfig.


Basicly you need to listen to localhost or 127.0.0.1. You can probably do it with:
listen-address=127.0.0.1


The last line of the configuration file says that all requests to sitesupport.net (including subdomains, like super.sitesupport.net) will be redirected to 192.168.33.10 (that's my virtual machine).

Also you need to add to the file /etc/dhcp/dhclient.conf (or create the file if it does not exist):
prepend domain-name-servers 127.0.0.1;


You also need to restart your system. Instead of restarting the system you may try to restart following services:
sudo service dnsmasq restart
sudo service NetworkManager restart


To check that everything works correctly, use command:
ping sitesupport.net

The output should show that the request was redirected to 192.168.33.10.

Thursday, May 21, 2015

vagrant: How to automatically update Guest Additions

To autmatically update Guest Additions on your vagrant machine you need to install vagrant-vbguest plugin. From the folder with Vagrantfile run the command:
vagrant plugin install vagrant-vbguest

Next time you start it with vagrant up, Guest Additions will be updated

Wednesday, May 20, 2015

fedora 21: How to add and preserve DNS server

Normally NetworkManager handels all DNS configuration. Every time when new network connection was established (?) it regenerates file /etc/resolv.conf which contains DNS server data, so editing this file is useless.

To add DNS server on top of the DNS servers list from your connections you need to create or edit file /etc/dhcp/dhclient.conf and add the following line:
prepend domain-name-servers 192.168.33.10;

Where 192.168.33.10 is address of DNS server.

After applying changes you need to reboot or restart NetworkManager service:
sudo service NetworkManager restart


Tuesday, May 19, 2015

fedora 21: How to mount remote filesystem via SSH

If you use vagrant for development you might need an access to the filesystem of the virtual machine. There is a way to mount a folder from your virtual machine to your local machine so you will be able to open and edit with your favourite code editor.

First step is to install fuse-sshfs package:
sudo yum install fuse-sshfs


Then you can mount folder from the virtual machine with command:
sshfs -o idmap=user vagrant@192.168.33.10:/home/vagrant /home/jsn/vagrant/vm

The first path is the path inside the virtual machine and the second one is for local machine.

Wednesday, April 29, 2015

fedora: How to automatically shutdown your system

The easiest way to shutdown your system is to use shutdown command:
sudo shutdown

It will start shutdown process immediaetely.

To shutdown your system in specific time use this command:
sudo shutdown 11:50


And to shutdown your system in 2 hours (120 mins) use this command:
sudo shutdown +120

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 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