Wednesday, January 16, 2019

openvpn pam_google_authenticator.so error in centos 7

This is the short story: I was trying to implement google OTP authentication while connecting to openvpn, so that in addition to normal password you need to pass timed token generated by your mobile app. My OS was CentOS 7.

The problem was that it didn't work after following some instruction on the web. (like this one http://dillidba.blogspot.com/2017/02/install-openvpn-on-centos-with-google.html)

My openvpn log was showing this error:

Wednesday, November 21, 2018

Python - How to wait for presence of an element with non empty text?

Hello!

Sometimes it's useful to wait for an element with non empty text. The question is how to do it with Selenium in Python? Pretty easy! You can find an answer below.

If xpath is absolute, then you can wait for your element with non empty text like this:
# xpath - xpath of your element

WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_xpath(xpath).text.strip() != '')

Tuesday, November 20, 2018

psql: FATAL: Ident authentication failed for user (Centos 7)

What's up?

In this article you will know how to fix this error:
psql: FATAL:  Ident authentication failed for user "username"
which happens when you try to connect as follows:
psql -U username -h 127.0.0.1 -d postgres

How to install/upgrade postgresql server from 9.2 to 9.6 on Centos 7

Hello!

This tutorial includes detailed steps on how to upgrade from old 9.2 postgresql server to new 9.6 postgresql server, with data migration. But you can also use this article if you want to install fresh 9.6 version - you just need to skip migration steps. You can also check this link for more information.

1. install PGDG RPM file for new postgresql server
sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm
(for the list of all options, check this link: https://yum.postgresql.org/repopackages.php)

Friday, November 9, 2018

How to install latest version of nginx in Centos 7

As of now current nginx version in centos 7 repo is 1.12.2, but latest version of stable nginx is 1.14.1.

In this article we will install latest nginx/1.14.1 in Centos 7.

1. Remove current version of nginx (1.12.2)
sudo yum remove nginx*

Wednesday, November 7, 2018

Running php site with php5-fpm behind nginx (centos 7)

If you're using latest version of nginx nginx-1.14.1-1.el7_4.ngx.x86_64, then by default in /etc/nginx/ you will have this files:

[centos@ip-172-31-37-214 ~]$ ls -la /etc/nginx
total 56
drwxr-xr-x.  3 root root 4096 Nov  7 07:41 .
drwxr-xr-x. 91 root root 8192 Nov  7 07:28 ..
drwxr-xr-x.  2 root root   89 Nov  7 07:37 conf.d
-rw-r--r--.  1 root root 1007 Nov  6 14:04 fastcgi_params
-rw-r--r--.  1 root root 2837 Nov  6 14:04 koi-utf
-rw-r--r--.  1 root root 2223 Nov  6 14:04 koi-win
-rw-r--r--.  1 root root 5170 Nov  6 14:04 mime.types
lrwxrwxrwx.  1 root root   29 Nov  7 07:28 modules -> ../../usr/lib64/nginx/modules
-rw-r--r--.  1 root root  643 Nov  6 13:54 nginx.conf
-rw-r--r--.  1 root root  636 Nov  6 14:04 scgi_params
-rw-r--r--.  1 root root  664 Nov  6 14:04 uwsgi_params
-rw-r--r--.  1 root root 3610 Nov  6 14:04 win-utf

Centos 7: uwsgi.sock failed (13: Permission denied) while connecting to upstream. How to fix.

In centos i had this issue in my nginx error.log:

uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: ...

After searching a bit, I found that this is because of centos SELinux permissions.

Wednesday, October 17, 2018

Druid indexing problem: Offsets out of range with no configured reset policy

I have the following set up:

1) kafka server
2) druid server (historical, broker, coordinator, overlord, middleManager, tranquility, zookeeper)

To get data from kafka I use kafka indexing service (supervisor), which is managed by overlord.

The problem is that recently I started seeing these errors and no data published to dataset:

Saturday, January 6, 2018

How to install python 3.5 in CentOS 7 from source

At the time of writing, repository of Centos 7 contains python 3 of version 3.4, which is not the newest. And sometimes it's useful to have newer version. For example, I needed python 3.5. And here I will show you how to install it. We will be installing it from source.

1. Update repositories and install couple packages:
sudo yum update
sudo yum install zlib-devel openssl-devel

Thursday, June 15, 2017

How to update openssl and/or install openssl 1.1.0 in centos 7 from sources

Updating openssl


After deploying new centos 7 distro, I checked version of openssl and it appeared to be very old (2013!!). To check openssl version, you can use this command:
openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
or this:
yum info openssl
Name        : openssl
Arch        : x86_64
Epoch       : 1
Version     : 1.0.1e
Release     : 60.el7_3.1

Then if you want to update it, simply run:
sudo yum update openssl
And if you check it again, it will show updated version:
openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
So this should include all security fixes and you're good to go.

But if you still want to install newer openssl alongside with the current one, below I will show how.

Monday, January 30, 2017

Caching for anonymous (non-authenticated) users in Django

Hi boys and girls,

Recently I was optimizing performance on some of my django sites and needed to cache all views for anonymous users, but still render for authenticated users. Django documentation is silent on this. I've also checked out stackoverflow, but people there recommend using templates, which I don't like. So below I will give you my version of how to solve that.

Saturday, January 21, 2017

Django Haystack - how to limit number of search results

Hello friends,

Recently I needed to limit number of search results in haystack and that was a bit of a challenge. So I decided to share it with you here.

I knew how to limit search results using old style views (haystack.views.SearchView):
from haystack.views import SearchView

class MySearchView(SearchView):

    #limit maximum results
    def get_results(self):
        return self.form.search()[:100]

Friday, January 20, 2017

Fabric how to set environment variable to fix encoding

Hi there,

Today I've encountered with one weird problem and decided to share it with you.

Here is what happens. When I ssh to server manually and run python script - everything works fine. But if I try to run the same script using fabric script, which connects to the same server, then it fails. In particular, it was encoding error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xaa' in position bb: ordinal not in range(128)

Thursday, January 5, 2017

How to scrape https website with proxies

Hi all,

My last post about scraping with proxies is quite old and I decided to write a newer version of it. In particular, today I will emphasize how to scrape https website with proxies.

There are also good news about requests library. Requests has not been supporting socks proxies for quite a long time, but in 2016 there was a new release of it. So now requests fully supports both http and socks proxies.

So let's get started. Below I will show you 4 different examples of how to scrape a single https page. First, we will scrape it with requests using socks and http proxies. Second, we will do the same using urllib3 library.

Monday, December 5, 2016

How to build uwsgi from source and run as a service

As you might have already noticed, I always deploy python applications using uwsgi and nginx. But I didn't write yet how to install uwsgi. Probably there is some version in repository, but I don't really care about it. I know it's old and not what I actually need.

I need to build uwsgi with plugin support, which would allow me to work both with python 3 and 2. Then I will create service config file, so that you can use it as service. Sounds good, isn't it? Let's do it then.

1. Download uwsgi and extract it
cd ~
curl -O http://projects.unbit.it/downloads/uwsgi-2.0.12.tar.gz
tar -xvzf uwsgi-2.0.12.tar.gz

Sunday, November 27, 2016

Why Python is not good for multi-threading?

Recently I was asked this question during screening interview at Yandex (Russian search engine), and they screened fairly well from me. They said: you're cool guy, but try again after a year. You're ok for junior, but not for senior position.

Long time ago I read on some blog that multi-threading is not good idea for Python. That's the only thing came to my mind at the interview. So I only answered that's not good idea, because it will require a lot of memory. Quite silly answer.

Then the interviewer said that it's somehow related to GIL. What's GIL??? It sounded like some kind of familiar and intelligent word to me.

After that, I googled this blog which explained me why Python is not good for multi-threading. Shortly speaking, all problems come from that GIL - Global Interpreter Lock. As result Python can only execute one thread at a time. If you'd like to start many threads, all of them will be competing for a single lock (GIL). Just remember that. You can't execute multiple threads simultaneously in Python. That's one of Python disadvantages and one of popular question at interviews.

Friday, November 25, 2016

How to deploy Trac on Debian Jessie with uwsgi and nginx

Dear all,

Today I'm going to deploy one popular bug tracking tool, which is known as Trac. At first look you may ask: why is it looking so weird? Was it designed in early 90's? Well, yes, interface is very minimalistic. But on the other side it has own benefits - it's absolutely free, written in Python and open source.

Below we will deploy Trac on Debian Jessie with Postgresql, uwsgi and nginx.

As everywhere else, I'm going to stick to my scheme, which I find convenient. If you have any suggestions what can be done better, feel free to tell me in comments or by email.

Also I'm assuming that you know how to install uwsgi and nginx packages. I will only show their trac configuration files. But if you need more info, read how to build uwsgi from source.

Saturday, November 19, 2016

Migration from MySQL to Postgresql with Django is easy as 1-2-3

Hi guys,

Short story: I started learning Django few years ago and created my first django website using mysql database. Over time I realized how much more powerful Postgresql is. And yesterday I decided to migrate my website from mysql to posgresql. But the main question - how?

First google search gave me suggestion - dump mysql database, then convert it to posgresql compatible format using some scripts. Check this page if you're interested.

I started doing it, but there were always some errors, even after conversion. For example, this:
ERROR:  column "blabla" is of type boolean but expression is of type integer

Friday, November 18, 2016

Launching Ionic app from external link, url capturing and redirect

Howdy guys,

I'm continuing my ionic series. Today let's talk about the following scenario:

Scenario: You have two web-apps: one for desktops and another (ionic) for mobiles. Both of them can send email notifications with some link, for example to verify email. Desktop and ionic urls are slightly different, but convertable from one to another. You always receive a desktop version of link to your email.

Task: When user clicks on that link from android device, we need to be able to open it in ionic app. In addition to that, ionic app should be able to parse that link and redirect to proper view.

ionic - auto install plugins on platform build

Hi there,

Today I will start my short series of posts about ionic, mobile framework for Android and iOS. Don't ask me how is it related to Python. I just needed to do some work for mobile.

One common task, that you need to do with ionic is to build your platform and install plugins. Let's choose Android as our platform.

To build android platform and install plugins you need to run commands like this:
cordova plugin add someplugin1
cordova plugin add someplugin2
ionic build android