Monday, October 17, 2022

Running Python (Flask) server on a shared hosting environment

If you have purchased a domain name through some other domain name registrar and not through your shared hosting provider, first you'll need to ...

1. Point nameservers to your shared hosting provider

The following instructions are for Namecheap: 

  • from the menu on the left side, open the Domain List and
  • click on button MANAGE next to your domain name.


  • Under NAMESERVERS, instead of Namecheap BasicDNS select Custom DNS.


  • Copy-paste name servers that your shared hosting has provided. 
  • Save the modifications by clicking on the green check mark.



2. Create an Addon Domain in shared hosting's cPanel

  • Once you are in cPanel, click on Addon Domains
  • Type in your new domain name and 
  • click on Add Domain button.

3. Setup Python App

  • Now go back to cPanel and click on Setup Python App.


  • Click on Create Application button.


  • Fill out the form by providing:

    • python version, 
    • application root directory (it was created by the system in step 2), 
    • application url (your domain name), 
    • main.py as application startup file and  
    • app as application entry point. 
    • Don't forget to add path to the passenger log file, for example logs/passenger.log
  • Once you do all that, click on CREATE button.

The app is created and your barebones python site is already running. You can check by it browsing to your new domain. If nameserver settings from step 1 still haven't propagated across the internet, you can open the site as a subdomain of your main domain site.

4. Install Flask

Once the python app is created at the top of the scree the following message will be displayed:

Enter to the virtual environment. To enter to virtual environment, run the command: ...

Copy the command, from cPanel open the terminal, paste and run the command there. Next, run: pip install Flask

To verify the installation, run: flask --version

After the installation is done, we'll modify our main.py application startup file. A minimal Flask application would be:

from flask import Flask


app = Flask(__name__)


@app.route
("/")

def hello_world():
    return
"<p>Hello, World!</p>"

Save the changes that you have made and restart the python app. Browse to your domain again and verify that everything is fine. You are done!

Next things you might consider doing:


Sunday, October 9, 2022

Awesome open source games

Disclaimer: I am using my computer to either learn or create something. Currently I don't play any games, so I haven't played these either. This post is actually for future myself who has a bit different priorities. 😃

Update 2024.05.21: two more lists of open source games, here and here.
Update 2023.05.30: found a list of FLOSS games on Steam.

The following three open source games have attracted my attention. Let me know in the comments about other open source games that you find to be awesome.

More about each game ...

 

0 A.D.

Inspired by: Age of Empires II: The Age of Kings (1999)
Website: https://play0ad.com
Code repository: https://trac.wildfiregames.com/browser
Programming languages: C++, JavaScript

 
Short description from the game's website:
0 A.D. is a free, open-source, historical Real Time Strategy (RTS) game currently under development by Wildfire Games, a global group of volunteer game developers. As the leader of an ancient civilization, you must gather the resources you need to raise a military force and dominate your enemies. 
[...] 
We intend to portray some of the major civilizations over the millennium of 500 B.C. to 500 A.D. (Hence the midpoint, zero.) 
[...] 
We put a strong emphasis on historical accuracy while developing 0 A.D. We plan all our units and all our buildings based on reconstructions of how the units and the buildings might have looked like in the ancient world. We even name them in the original languages, such as Greek and Latin.

 

Endless sky

Inspired by: Escape velocity (1996) → Privateer (1993) → Elite (1984)
Website: https://endless-sky.github.io
Code repository: https://github.com/endless-sky
Programming languages: C++

Short description from the game's website:

Endless Sky is a 2D space trading and combat game similar to the classic Escape Velocity series. Explore other star systems. Earn money by trading, carrying passengers, or completing missions. Use your earnings to buy a better ship or to upgrade the weapons and engines on your current one. Blow up pirates. Take sides in a civil war. Or leave human space behind and hope to find friendly aliens whose culture is more civilized than your own.

Small note: Writing this post I found out that Elite (1984) precedes Sid Meier's Pirates (1987),  I always thought it's the other way around.


Freeciv

Inspired by: Civilization II (1996)
Website: https://www.freeciv.org, https://www.freecivweb.org
Code repository: https://github.com/freeciv
Programming languages: C (desktop); JavaScript, HTML5 and WebGL (web)

Short description from Freeciv Wikipedia page:

Freeciv is a single and multiplayer turn-based strategy game for workstations and personal computers inspired by the proprietary Sid Meier's Civilization series. It is available for most desktop computer operating systems and available in an online browser version. [...] The game's default settings are closest to Civilization II, in both gameplay and graphics, including the units and the isometric grid. Freeciv is playable online at fciv.net and freecivweb.org

Players take the role of tribal leaders in 4000 B.C. who must guide their peoples through the centuries. Over time, new technologies are discovered, which allow the construction of new city buildings and the deployment of new units. Players can wage war on one another or form diplomatic relationships.

The game ends when one civilization has eradicated all others or accomplished the goal of space colonization, or at a given deadline. If more than one civilization remains at the deadline, the player with the highest score wins. Points are awarded for the size of a civilization, its wealth, and cultural and scientific advances.

Tuesday, October 4, 2022

Typing curly braces { in Eclipse

By default Ctrl+Alt+B keystroke acts as skip breakpoints shortcut. You need to unbind it by ...

  1. ... going to Window > Preferences
  2. In the search box on the left side type in binding
  3. Click on Keys under General.
  4. Now in the search box on the right side type in Alt+B.
  5. Click on Skip All Breakpoints list item.
  6. Click on Unbind Command button.
  7. Click on Apply and Close button.

All thanks go to StackOverflow answer here.

Saturday, October 1, 2022

Force HTTPS and non-www domain via .htaccess file

RewriteEngine On

# match any URL with www and rewrite it to https without the www
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]

# match urls that are non https (without the www)
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)(.*) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Don't forget to put the snippet at the top of the .htaccess file.

All thanks go to StackOverflow answer here.