Hosting Static Website using FastAPI and Uvicorn

Here is an example program that allows you to host a static website with HTML, CSS and JPEG files using FastAPI and Uvicorn. The example assumes that all the static files are located inside the “site” directory and its sub-directories (e.g. css, images sub-directories etc).

from os.path import isfile
from fastapi import Response
from mimetypes import guess_type
from fastapi.responses import FileResponse
from fastapi import FastAPI

app = FastAPI()

@app.get("/{filename}")
async def get_site(filename):
    filename = './site/' + filename

    if not isfile(filename):
        return Response(status_code=404)
    else:
        return FileResponse(filename)

@app.get("/")
async def get_site_default_filename():
    return await get_site('index.html')

All these images were generated by Google’s latest text-to-image AI – The Verge

https://www.theverge.com/2022/5/24/23139297/google-imagen-text-to-image-ai-system-examples-paper

In each case, the text at the bottom of the image was the prompt fed into the program, and the picture above, the output. Just to stress: that’s all it takes. You type what you want to see and the program generates it.

How to reset MySQL root password on Ubuntu

Here are the steps to reset your MySQL root password on a Ubuntu server.

Step 1: Edit the file at /etc/mysql/my.cnf and add the following two lines to the end of the file.

[mysqld]
skip-grant-table

Step 2: Restart the MySQL server. The server will now skip over the password authentication.

sudo systemctl restart mysql.service

Step 3: Log in to MySQL server. Press enter when prompted for password. You should be able to login without password now.

mysql -u root -p
Enter password:

Step 4: Update the password of the root user.

update mysql.user set authentication_string = CONCAT('*', UPPER(SHA1(UNHEX(SHA1('yournewpasswordhere'))))) where user = 'root' and host = 'localhost';

Step 5: Exit MySQL, remove or comment away the two lines in /etc/mysql/mycnf, and restart the MySQL server.

sudo systemctl restart mysql.service

You should now be able to login to the MySQL server using your new password.

Creating the Commodore 64 – The Engineer Story

https://spectrum.ieee.org/commodore-64

In January 1981, a handful of semiconductor engineers at MOS Technology in West Chester, Pa., a subsidiary of Commodore International Ltd., began designing a graphics chip and a sound chip to sell to whoever wanted to make “the world’s best video game.” In January 1982, a home computer incorporating those chips was introduced at the Winter Consumer Electronics Show in Las Vegas, Nev. By using in-house integrated-circuit-fabrication facilities for prototyping, the engineers had cut the design time for each chip to less than nine months, and they had designed and built five prototype computers for the show in less than five weeks. What surprised the rest of the home-computer industry most, however, was the introductory price of the Commodore 64: $595 for a unit incorporating a keyboard, a central processor, the graphics and sound chips, and 64 kilobytes of memory instead of the 16 or 32 that were then considered the norm.