Search This Blog

Programmer blog

Posts

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…

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…

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

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

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.

Tmux is a handy terminal manager that allows you to switch between terminal sessions easily. Without losing history or windows upon ssh disconnects or similar. It is like screen, just better. (First of all because of using client-server based technology... )

Here is my minimal keyboard shortcuts guide that allows you to start using Tmux in a blink of an eye. Endless advanced commands and hotkey combinations you could always find by entering "man tmux" in a terminal.

Tmux is installed quite easily in most of common linux based systems. Just type:Ubuntu:$ sudo apt-get install tmux CentOS:$ sudo yum install tmux
This allows you to start using by starting it with$ tmux a || tmux new
This command first tries to attach to existing running tmux instance and creates new in case it is not found.

Ctrl+b d - Will allow you to disconnect at any time. (This is also a way it is happening when you loose ssh session. How to connect - look earlier)