Monday, May 2, 2016

How to format USB stick as FAT32

First step is to find the name of the USB stick in the system:
sudo fdisk -l
In my case the name of the device is /dev/sdc If the USB stick is mounted, unmount it with command:
sudo unmount /dev/sdc
Finally, run the command to format USB stick:
mkdosfs -F 32 -I /dev/sdc

Monday, April 18, 2016

apt-get: Install package with specific version and hold it on the next upgrade

If you need to install specific version of the package in your system, you can list all available package versions with the command:
apt-cache madison varnish
After you know the package version you can install it with:
sudo apt-get install varnish=4.0.2-1
To hold the package on the selected version during the next upgrade:
sudo apt-mark hold varnish
You can also "unhold it" with:
sudo apt-mark unhold varnish

Sunday, March 13, 2016

fedora: Install accidentally removed sqlite package

If sqlite package (or, for example, sqlite-libs package) was accidentally removed from your system, you can't reinstall it using dnf or yum because they depend on it. To fix this problem, download missing rpm package from https://admin.fedoraproject.org/pkgdb/package/rpms/sqlite/. From the downloaded file location, run command:
rpm2cpio sqlite-libs-3.11.0-3.fc23.x86_64.rpm | cpio -idmv
It will create usr folder with extracted files. Run next command to copy them to the right location:
sudo cp -R usr/ /
Pay attention to the package architecture. You should be able to use dnf again. It would be good to reinstall missed package with dnf again:
sudo dnf --best --allowerasing install sqlite-libs

Thursday, February 18, 2016

Set up logging with Flask and gunicorn

Let's say that we want to be able to log in the specified log file and syslog. Our application - is a simple app.py file. The first step, I suggest, is to set logger name:
import os

from flask import Flask


app = Flask(__name__)
app.logger_name = "flask.app"

# ...

if __name__ == "__main__":
    app.run()
You can log in your project like this:
app.logger.info("Hello")
A log configuration file for the gunicorn may look something like this:
[loggers]
keys=root, gunicorn.error, gunicorn.access, requests.packages.urllib3.connectionpool, __main__

[handlers]
keys=log_file, syslog

[formatters]
keys=generic

[logger_root]
level=INFO
handlers=log_file, syslog

[logger___main__]
level=DEBUG
handlers=log_file, syslog
propagate=0
qualname=__main__

[logger_gunicorn.error]
level=INFO
handlers=log_file, syslog
propagate=0
qualname=gunicorn.error

[logger_gunicorn.access]
level=INFO
handlers=log_file, syslog
propagate=0
qualname=gunicorn.access

[logger_requests.packages.urllib3.connectionpool]
level=WARN
handlers=log_file, syslog
propagate=0
qualname=requests.packages.urllib3.connectionpool

[handler_syslog]
class=logging.handlers.SysLogHandler
formatter=generic
args=()

[handler_log_file]
class=logging.FileHandler
formatter=generic
args=('/home/myuser/log/gunicorn.log',)

[formatter_generic]
format=%(asctime)s [%(process)d:%(name)s:%(lineno)s] [%(levelname)s] %(message)s
datefmt=%Y-%m-%d %H:%M:%S
class=logging.Formatter
The last step is starting gunicorn:
gunicorn app:app --log-config /home/myuser/gunicorn_logging.conf

Conditions in the Vagrantfile

Every developer could have different hardware configuration. Let's say one is ready to provision a virtual machine with 4 cpus and another - only with 2 cpus. It would be nice to handle this situation with environmental variables:
Vagrant.configure(2) do |config|
  config.vm.box = "box-cutter/debian81"

  config.vm.network "private_network", ip: "192.168.33.10"
  config.ssh.forward_agent = true

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "4096"
    if ENV.has_key?('VAGRANT_CPUS')
      vb.cpus = ENV['VAGRANT_CPUS']
    else
      vb.cpus = "2"
    end
  end
end
With that config the number of the provisioned cpus can be controled via VAGRANT_CPUS environmental variable.

Gnome: How to record a screencast

Gnome 3 has in-built screencast functionality. To start record your screen simply press
Ctrl + Shift + Alt + R
The indicator (a red circle) will appear in the panel, informing you that the recording has started. Default video length is limited to 30s, what might be not enough in most cases. To adjust this parameter install dconf Editor and go to the:
org.gnome.settings-daemon.plugins.media-keys
And look for max-screencast-length to adjust.

Tuesday, January 26, 2016

komodo: Use custom version of the jshint

Komodo has an outdated version of the jshint. If you want to use, for example, moz:true option, you need to upgrade it. I tried it multiple times and never succeed. The problem was not in komodo (at least that was the developers say) but in jshint. All latest versions of the jshint does not work with komodo. The latest version of the jshint that is known to work with komodo is 2.6.0. To configure komodo to use jshint 2.6.0, open File -> Preferences -> Syntax Checking -> Language: Javascript and point Custom linter to the downloaded file: The version 2.6.0 is somewhere from the early 2015 but still much better then the default one.