Blog | Emin Mastizadahttps://mastizada.com/blog/2024-03-28T23:42:07.569794+00:00Blog#movingtogitlab2018-06-05T11:39:51+00:002024-03-28T23:42:07.569794+00:00Emin Mastizadahttps://mastizada.com/blog/author/mastizada/https://mastizada.com/blog/movingtogitlab/<p>When you talk about open source, first thing that comes to mind is probably Github. It is an awesome "social network" for developers and hosts lots of projects. Also it makes working on team or open source projects a lot easier and have awesome integrations (Travis, Coveralls and so on). Github also provides service for open source for free and it is a rare case nowadays that a free service doesn't make you it's product.</p>
<p>But Github also a closed source by itself and making open source projects to <strong>depend</strong> on closed source platform isn't a good idea and never was. Free software supporters used it anyway as it was independent and had user's trust.</p>
<p>Github was losing money and needed to find a way to increase it's profit. After all, it is a for-profit company and it's investors needs money. Giving too much power to such platforms always ends badly as needs for profit puts community needs behind. More on that is stated in this article: <a href="https://www.wired.com/2015/06/problem-putting-worlds-code-github/" target="_blank" title="Wired: The Problem With Putting All the World's Code in GitHub">Wired article</a></p>
<p>Another alternate to Github is <a href="https://bitbucket.org/" target="_blank" title="Bitbucket website">Bitbucket</a>, <span style="text-decoration: underline;">owned</span> by Atlassian. It provides free private repositories with limited number of members for personal use. It is more like cheaper version of Github for enterprise use and has better integration with Atlassian products like Jira.</p>
<p>Gogs, Gitea, Gitlab CE and other self-hosted solutions - For private usage, you can just use git itself without fancy UI. These solutions are good for projects developed by multiple groups and community. However, to make contribution to your project others will need to register on your system, configure their profiles and get used to you UI and issue management. It is much better than using maillists or FTP but not great. The main point behind Github is the social part. You use it for your personal projects, for work related projects and at the same time you can contribute to other projects using the same network. That attracts a lot of people to the project and that is the main reason for many free and open source projects to choose Github, Bitbucket or Gitlab.</p>
<p>Gitlab uses open source business model and offers Community Edition (MIT License) which you can host by yourself and has most of the key features of Gitlab. So even if it makes mistakes in future, community can easily fork it and continue development - making it future-proof. It is also a social coding platform like Github and more projects are starting to use it. It also offers unlimited private repositories both for personal and for enterprise use, it has own Continuous Integration & Deployment (CI) free to use. Another great news, they are going to implement federated merge requests (pull requests) such that, you can use both private hosted version and centrialized ones and send merge requests (Github's Pull Requests) to projects using both versions - Gnome uses gitlab.gnome.org and this feature will allow you to make contribution to Gnome projects directly from Gitlab.com or other networks using Gitlab. You can check some awesome features at <a href="https://about.gitlab.com/pricing/self-hosted/feature-comparison/" title="this page">this page</a>.</p>
<p></p>
<h2>Why moving now?</h2>
<p>As you already know, Microsoft bought (agreed?) to buy Github for $7.5 billion. Well, that is good for Github as they will pay their investors and they will have resources for the future. Also Microsoft makes a lot of contributions to open source projects since Satya Nadella became CEO and they are supporting free software events. More contributors, more free and open source projects are better for the community and we like it. But recovering trust takes more time specially for a company that was so evil agains open source in the past, it's <a href="https://en.wikipedia.org/wiki/Embrace,_extend,_and_extinguish" target="_blank" title="Wikipedia article Embrace, extend, and extinguish">Embrace, extend, and extinguish</a> and even has problems nowadays: <a href="https://www.infoworld.com/article/3137496/open-source-tools/no-microsoft-does-not-love-open-source.html" target="_blank" title="No, Microsoft does not love open source article">No, Microsoft does not love open source</a>. May be one day they will gain trust but it is too soon.</p>
<p>Will Microsoft improve Github and leave it independent after spending so much money and more later (Github's infrastructure requires a lot of money and paid users do not cover it yet) or will it end like Skype, Nokia and many other projects? Maybe more limitations for free users, requiring MS Live account, exclusive functionalities for their Azure platform and their Visual Studio Code and so on. We will see later, but that is not point and it shouldn't be reason to leave the platform. Microsoft buying Github reminds us base problem with Github - being closed source, for-profit and hosting most of the major free and open source projects. That gives huge powers to Microsoft over free software projects and it is completely wrong - They can use it to eliminate alternates by providing locking features that only can be used in Github, which is stated well in "<a href="https://en.wikipedia.org/wiki/Embrace,_extend,_and_extinguish" target="_blank" title="Wikipedia article Embrace, extend, and extinguish">Embrace, extend, and extinguish</a>" article. A major corporation like Microsoft, Google, Facebook or Apple should not have such power. Using Github for such projects already was a mistake and continuing to use is worse.</p>
<p>For that reason I already started to move our Free Software Community in university to Gitlab (community exposes a sample behaviour for new members) and other open source projects that I'm maintaining. Also moved private repositories from Github and Bitbucket to avoid usage of multiple networks. Of course it is not the end for Github and most will continue to use it for some other projects (just like #DeleteFacebook, it is a social network and won't die unless most of it's users related to you leaves to the same platform as you) if Microsoft will not ruin it. Gitlab seems the safest "social" solution for now.</p>
<p>Additional reading: <a href="https://devrant.com/rants/1459012/ok-now-there-is-quite-big-movement-from-github-to-gitlab-https-bit-ly-2xjwgds-it" target="_blank" title="article about moving from Github to Gitlab by amatrelan">Ok, now there is quite big movement from GitHub to GitLab</a></p>Flask on Apache with mod_wsgi2018-05-23T20:46:48+00:002024-03-28T11:10:55.391729+00:00Emin Mastizadahttps://mastizada.com/blog/author/mastizada/https://mastizada.com/blog/flask-on-apache-with-mod_wsgi/<p>Nowadays making a proxy from an nginx to a gunicorn socket running on supervisor or systemd makes things so easier that most of us even forgot how deployment was before. Recently I was asked to deploy a flask application on already working Apache2 instance. In this blog post I will describe steps and problems using mod_wsgi on Apache.</p>
<p>First of all, install python, pip and mod_wsgi: <code>apt install python3-dev python3-pip libapache2-mod-wsgi</code></p>
<p>Restart <code>apache2</code> service and verify that wsgi module is loaded: <code>sudo apache2ctl -M|grep -i wsgi</code></p>
<p>Create a <code>projectname.wsgi</code> file in your project:</p>
<pre>import sys<br/>sys.path.insert(0, '/path/to/project')<br/><br/>from app import app as application<br/>application.root_path = '/path/to/project'</pre>
<p>The first thing will add your python files to the python path, that is needed to find the app.py file (where your flask app is located). The second part will tell the application where the root is, it is required for loading templates.</p>
<p>Create a configuration file (<code>projectname.conf</code> - .conf extension is required for the new version of Apache) for your project under <code>/etc/apache2/sites-available</code>:</p>
<pre><VirtualHost *:<PORT>><br/> ServerName <DOMAIN.NAME><br/> WSGIDaemonProcess <projectname> user=<user> group=www-data threads=2<br/> WSGIScriptAlias / /path/to/project/projectname.wsgi<br/> <Directory /path/to/project><br/> WSGIProcessGroup <projectname><br/> WSGIApplicationGroup %{GLOBAL}<br/> Order deny,allow<br/> Allow from all<br/> </Directory><br/> Alias "/static/" "/path/to/project/static/"<br/> <Directory /path/to/project/static/><br/> Order allow,deny<br/> Allow from all<br/> </Directory><br/> ErrorLog /path/to/logs/error.log<br/> CustomLog /path/to/logs/access.log combined<br/></VirtualHost></pre>
<p>Link the configuration file to the enabled folder:</p>
<p><code>cd ../sites-enabled</code> & <code>ln -s ../sites-available/projectname.conf projectname.conf</code>.</p>
<p>Reload apache2 service and check if the website is online.</p>
<p>Most notable difference between gunicorn is that you will not be able to open files from the relative path. You can use <code>current_app.root_path</code> to access path and it is true for all plugins too (in my case, one of the plugins was storing a session file in the project root). Also defining <code>PROJECT_ROOT</code> can be helpful: <code>PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))</code></p>Date/Time Localization in Django (python-side)2017-03-12T06:40:15+00:002024-03-28T21:43:21.874703+00:00Emin Mastizadahttps://mastizada.com/blog/author/mastizada/https://mastizada.com/blog/datetime-localization-in-django-python-side/<p>There are two sides in localization in Django framework: Templates and Python-side.</p>
<p>There are a lot of good stuff about template side in <a href="https://docs.djangoproject.com/en/1.10/topics/i18n/" target="_blank" title="Internationalization and localization">Django</a> <a href="https://docs.djangoproject.com/en/1.10/topics/i18n/formatting/" target="_blank" title="Format localization">Documentation</a>, how ever what if you need to get time using <strong>datetime</strong> module?</p>
<p>Lets go over <code>date.today</code> using "%B %Y" <a href="https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior" target="_blank" title="Python datetime formats">format</a>:</p>
<pre>>>> from datetime import date<br/>>>> today = date.today()<br/>>>> print(today.strftime("%B %Y"))<br/>March 2017</pre>
<p>What if I need this for subject of an e-mail or sms message that will be sent from django app?</p>
<p>Let's assume that we have <code>user</code> object, and it has <code>CharField</code> language with value 'ru'. First of all, we will need to activate language:</p>
<pre>>>> from django.utils.translation import activate<br/>>>> activate(user.language)</pre>
<p>Our e-mail subject will be "Topics for March 2017" and in Russian "Темы для Март 2017":</p>
<pre>>>> from django.utils.translation import ugettext_lazy as _<br/>>>> subject = _("Topics for {date}").format(date=today.strftime("%B %Y"))<br/>>>> print(subject)<br/>Темы для March 2017</pre>
<p>As you can see, month stays in English. In that case one possible solution can be to parse month name ("March"), use it's translation and add only year from <code>today.year</code>:</p>
<pre>>>> month_name = _(today.strftime("%B"))<br/>>>> subject = _("Topics for {month}, {year}").format(month=month_name, year=today.year)<br/>>>> print(subject)<br/>Темы для Март, 2017</pre>
<p>Another way is to use django.utils.formats function:</p>
<pre>>>> from django.utils import formats<br/>>>> date = formats.date_format(today, format="YEAR_MONTH_FORMAT", use_l10n=True)<br/>>>> subject = _("Topics for {date}").format(date=date)<br/>>>> print(subject)<br/>Темы для Март 2017 г.</pre>
<p>If you have <code>USE_L10N = True</code> in settings, no need for <code>use_l10n</code> attribute.</p>
<p>Second way is more practical and first gives you better control for localization (like adding extra words for different locales).</p>
<p>You can <a href="https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#std:templatefilter-date" target="_blank" title="all allowed date format strings">find here all allowed date format strings</a>.</p>
<p></p>
<p>Hope it helped you and if you have a better idea to solve that problem, please, write them in comments.</p>Chunked-Encoded data error in php cURL requests2015-05-29T13:12:20+00:002016-12-25T04:05:29.204165+00:00Emin Mastizadahttps://mastizada.com/blog/author/mastizada/https://mastizada.com/blog/chunked-encoded-data-error-in-php-curl-requests/<p>Few days ago we got a new problem, one part of our website stopped working, we used guzzle with Symfony2 to make requests to our RESTful API. After checking logs the only thing I could find was something like that:</p>
<p><code>[curl] 56: Problem (2) in the Chunked-Encoded data [url]</code></p>
<p>We changed guzzle to guzzlehttp as it was outdated, tried few other things (creating request and adding data, json request, making request header and body and sending all at once (client->put) but nothing helped. Then focused on main problem, cURL.</p>
<p>Actually it was problem of cURL itself (yep, that is very strange) and after updating it to 7.36 version problem solved by itself.</p>
<p>Steps:</p>
<ol>
<li><code>sudo add-apt-repository ppa:costamagnagianfranco/ettercap-stable-backports</code></li>
<li><code>sudo apt-get update && sudo apt-get install curl</code></li>
</ol>
<p></p>
<p><em>Happy Coding...</em></p>How to disable some hotkeys in Ubuntu2015-02-27T13:15:52+00:002023-07-13T17:16:23.470191+00:00Emin Mastizadahttps://mastizada.com/blog/author/mastizada/https://mastizada.com/blog/how-to-disable-some-hotkeys-in-ubuntu/<p>I mostly don't use mouse, and doing everything from keyboard while working. But the most annoying thing is that while making something awesome in code editor or reading something good in firefox you can suddenly press Ctrl+Q (which exits from browser immidiatly without warnings) or Alt+F4 when you want to press Alt+F3. Everytime I loose time because of that hotkeys.</p>
<p>So, today finally I changed my keyboard layout after closing code editor with unsaved code and important sorted data.</p>
<p>In Ubuntu just open System Settings and then Keyboard:</p>
<p><img alt="Ubuntu System Settings" height="300" src="https://mastizada.com/media/uploads/blog/linux-hotkeys/.thumbnails/settings.png/settings-377x300.png" title="Ubuntu Settings" width="377"/></p>
<p>Then edit current key combination to make it hard and unique (click once on it to change):</p>
<p><img alt="Ubuntu Close Window Hotkey" height="300" src="https://mastizada.com/media/uploads/blog/linux-hotkeys/.thumbnails/closekey.png/closekey-534x300.png" title="close window hotkey change" width="534"/></p>
<p>Now go to Custom Shortcuts and add new keys with /bin/false command which will do nothing:</p>
<p><img height="300" src="https://mastizada.com/media/uploads/blog/linux-hotkeys/.thumbnails/falsekeys.png/falsekeys-535x300.png" width="535"/></p>
<p>After adding combinations here these keys will do nothing and you will never have such problem again. Just remember changed hotkey to not search later why they are not working :D<br/><br/>Happy coding...</p>