Posts

PostgreSQL DB with pgAdmin4 access through SSH tunnel

Image
Despite using console most of the time I have a preference to edit PostgreSQL databases through UI. Especially when it comes to remote side. Usually one can access this through $ psql command. However this tends to writing raw SQL queries and a lot of typing in overall.
Here is a way to do it with UI. First one needs to make a tunnel.Command is fairly simple:
ssh -fNg -L 5555:localhost:5432{username}@{host.com} One has a tunnel afterwards. This command opens a SSH connection in the background mapping your local port 5555 to your server’s port 5432 (Postgres’ default port). To understand one can observe the meaning of the flags via $ man ssh to see what each of these flags doing.
 It can be accessed via localhost tools like pgAdmin4 at localhost and port 5555
DB config would look like so:

Run Flask with Debug in PyCharm

Image
I have gotten to setting UP a Flask environment for a project recently. Was completely puzzled by how to run this. I have used to running Django project with python manage.py script. This means pointing out a PyCharm interpreter into a certain point of entry, that is also a .py file also.

In flask way of starting things there is another approach however. Here it is in Flask Docs.
It states to set a variable FLASK_APP and then run a flask run command. This will confuse running a python script way of a project being run. Thus to fix this one needs to set a path to flask binary file. It usually is within a virtual environment binary directory, place where your python interpreter resides.

So to set debugging one needs to set path to script binary one needs:
Script: /path/to/env/bin/flaskScript parameters: runEnvironment variable FLASK_APP=app.pyEnvironment variable FLASK_DEBUG=TrueSet working directory back to your app path (It changes automatically according to script being set) So my wil…

Promise -fication of JS calls.

Image
Found a new pattern to use recently that is called Promise. I really like the way ES6/7 brings new thinking patterns into life nowdays. Here is Promise used instead of old pattern.

It was to give JS method a callback function. This splitting code and making a lot of possibilities for error to come out in this place.

One would write old times according to MDN:
functiongreeting(name){alert('Hello '+name);}functionprocessUserInput(callback){varname=prompt('Please enter your name.');callback(name);}processUserInput(greeting); And now it is made with Promise pattern like so:
letpromise=newPromise((resolve,reject)=>{resolve(prompt('Please enter your name.'));});promise.then((name)=>{alert('Hello '+name);}); In general and briefly this now helps to avoid 'callback hell' with functions passed as arguments and write asynchronous code a sort of in synchronous manner.

This all becomes extra useful upon one having need to load set of data from a differe…

Vagrant error: * Unknown configuration section 'hostmanager'.

Sometimes you get a vagrant environment or boilerplate with a Vagrantfile config in there and do a vagrant up command. And see some errors. like this:
There are errors in the configuration of this machine. Please fix the following errors and try again:Vagrant:* Unknown configuration section 'hostmanager'.
To fix this one needs:
$ vagrant plugin install vagrant-hostmanager Installing the 'vagrant-hostmanager' plugin. This can take a few minutes... Fetching: vagrant-hostmanager-1.8.6.gem (100%) Installed the plugin 'vagrant-hostmanager (1.8.6)'! So command to fix this as follows:
vagrant plugin install vagrant-hostmanager

POP3 Mock (Fake) server using python script

Having a need in POP3 server for my debugging purposes I have used this script.
Letting it to be here in case of anyone would need to do something similar.
Usage is:
$ python pypopper.py 110 email_file.eml

"""pypopper: a file-based pop3 serverUseage:    python pypopper.py <port> <path_to_message_file>"""import logging import os importsocketimport sys import traceback logging.basicConfig(format="%(name)s %(levelname)s - %(message)s")log= logging.getLogger("pypopper") log.setLevel(logging.INFO) class ChatterboxConnection(object): END ="\r\n" def __init__(self, conn): self.conn = conn def __getattr__(self, name):return getattr(self.conn, name) def sendall(self, data, END=END):if len(data)<50: log.debug("send: %r", data)else: log.debug("send: %r...", data[:50]) data += END self.conn.sendall(data) def recvall(self, END=END): …

Install Docker under Ubuntu 14.04 (Trusty)

Image
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 docker.io sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker sudo sed -i '$acomplete -F _docker docker'/etc/bash_completion.d/docker.io
2. Now run it with:
sudo apt-get install lxc-docker
3. Make it run on system boot:
sudo update-rc.d docker.io 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.

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:
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm sudo rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
CentOS 6:
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 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 /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo /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:
[remi] name=Les RPM de remi pour Enterprise Linux 6- $basearch #baseurl=http://rpms.famillecollet.c…