ImageMagick

I had a chance to use the ‘imagemagick’ utility today, it has been some time. I downloaded an image and wanted to pad it on both the.sides in order to use it on my blog.

First, I needed to check its width in order to see if it has been changed, after the padding operation.

magick identify  gravity-force-experiment-example_1308-105498.jpg.png

Then, I issued the command to pad the image on both the sides.

magick gravity-force-experiment-example_1308-105498.jpg.png -gravity center -background white -extent 1000 out.png

Finally, I checked the image width again.

magick identify out.png 

OneDrive Public View

It is part of my ‘storage/view design’, to have multiple ‘copies’ and multiple views of my blog data. Blog data includes post text, title and media in the post. OneDrive provides a storage backup facility as well as a public view, so it fits the purpose of this design. I have put the blog post data on OneDrive at a path, it can be viewed In the public view provided by OneDrive.

OneDrive Installation

In my last operation of cleaning up my system, I must have removed Microsoft OneDrive. So, it was time today, to reinstall it. It is actually a part of the ‘storage/view design’ that I am working on, in order to have a good backup of my blog data, as well as, a publicly available multiple views for it.

Delete Error

In continuation from the last post, the backup download was taking some time, so, I checked the home directory. And, it has some old unneeded data. I tried deleting it, in order to make the backup process fast. But, there is an error in deleting the directories. There is an access related problem.

Hosting Issues

I ran into some troubles with my hosting of amol9.com, it is a shared hosting space. I wanted a wiki there, so I installed one using a software installer available via the hosting control panel. The software got installed. But, it did not work. I examined the error logs and I think that the wiki software has installed an entry in the Apache configuration. It might be redirecting all the requests to the wiki start page script, this is the page that errors refer to.

One solution that came to my mind was to examine the Apache configuration file(s) and edit the entry there, if it is there. Then, I would remove the files related to the software installed and then I would install some working software, likely in a subdirectory, installing the software on the main directory of the site must have caused this problem, making other software unavailable. But, the Apache configuration file(s) are not directly available, what is available is access to some entries via browser interface, entries which are not useful for the purpose of solution of this issue.

The only way forward seems to be to remove all the installed software and reinstall a working software. This may not be straight forward. I might have to contact the technical support for the hosting and they might even move the hosting space. Considering this, I am moving a copy of the site to my laptop, I am downloading an archive of the home directory.

ImageBot Setup

I am going through some old code that I have written. This particular package, published on PyPI uses the ‘scrapy’ Python package to scrape a website for images.

The setup configuration can be viewed inside the ‘setup.py’ file. This file is generally added to a Python project to make it a package easily available for installation via some tool like, ‘pip’ and via some website like, ‘pipy.org’. The ‘setup.py’ file makes it.easy to mention the dependencies, which can be automatically installed by the package installer. This ‘imagebot’ package depends on a few external Python packages, like, ‘scrapy’, a Python scraping package, ‘PIL/Pillow’, a Python image processing library and ‘mutils’, a Python library written by me to include commonly used Python code. I think, that, this ‘setup.py’ is the file executed first by a package installer. One can mentioned metadata, like, author, version, categories, email, description, etc. in this file. One can also include additional code execution in this file, the code necessary to be executed at the installation time fits this kind of inclusion.

import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, find_packages
import platform
import imp
from imagebot.version import version
with open('imagebot/env.py', 'w') as f:
f.write('env = \'release\'\n')
install_requires = ['scrapy>=1.0.1', 'mutils>=1.0.4']
try:
imp.find_module('PIL')
except ImportError:
install_requires.append('Pillow')
entry_points = {}
entry_points['console_scripts'] = ['imagebot=imagebot.main:main']
setup( name = 'imagebot',
description = 'A web bot to crawl websites and scrape images.',
version = version,
author = 'Amol Umrale',
author_email = 'babaiscool@gmail.com',
url = 'http://pypi.python.org/pypi/imagebot/',
packages = find_packages(),
package_data = {'imagebot': ['tables.sql']},
scripts = ['ez_setup.py'],
entry_points = entry_points,
install_requires = install_requires,
classifiers = [
'Development Status :: 4 - Beta',
'Environment :: Console',
'Framework :: Scrapy',
'Framework :: Twisted',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 2.7',
'Topic :: Internet :: WWW/HTTP :: Indexing/Search'
]
)
with open('imagebot/env.py', 'w') as f:
f.write('env = \'dev\'\n')

Adding SSH Key to GitHub

I am trying to add an SSH key to my GitHub account. It is running into problems. It is my first time with GitHub via a Google account.

Making a City Builder

I am trying my hand in the area of world building. I have written a few stories and have a small collection of characters, buildings, creatures, etc. I also have all these in a city. In order to make the world, I need to add a picture, which could be created using some kind of map maker software. One option is any city builder game which would suffice for the purpose. Another option which I came up with today is to make a tool myself, using AI agent.

I settled on the AI agent option. I can make a tool easily, in a way that I desire. I used chatGPT. Code is attached below.

Here is the prompt: “make an isometric city builder in python; objects available are house, tower, wall; without roof, show floors”.

It did generate a tool for building a city, it works. The image above shows the tool.

Lexical Analyzer Implementation

To perform the tokenization of input program, we need to implement lexical analyzer. According to the reference site, https://www.geeksforgeeks.org/compiler-design/introduction-of-lexical-analysis/, DFA, or, Deterministic Finite Automaton seems to be the machine to be used. It takes me back to the college days, I think, the subject was ‘Principles of Compiler Design’ with a book of reference being the one written by Aho, Ullman. DFA seems to be the machine for it. The word ‘deterministic’ indicates that there are no ambiguities in the operation of the machine. There is a symbolic representation of the machine, available if you search. One characteristic of the machine seems to be ‘no memory’, indicating that, no memory is needed for the operation of the machine, like a stack or a list, input comes in and is converted to output, using rules, I think, simple regex rules suffice for the programming languages.

It is interesting to note that, ‘Regular Expression’ is itself classified as DFA.

(𝑄,Σ,𝛿,𝑞0,𝐹) is the 5-tuple that represents this machine. The description can be found on Google. Implementation of a lexical analyzer will fit this machine description.

Q: Set of states, initial state, intermediate states, final state of token table
Σ: alphabet, input character set, a-z, 0-9, other symbols
𝛿: set of rules, regexes
𝑞0: initial state, empty token table
F: final state, output token table

Lazy Language Interpreter Design

Sample program:

int main:
  v = 10
  for i: 1 to v
    write “hello”

The first step in the stabdard practice of implementing interpreters seems to be to tokenize input. This seems easy. Here are the tokens:

LexemesTokens
intKEYWORD
mainKEYWORD
:KEYWORD
vIDENTIFIER
=OPERATOR
10VALUE
forKEYWORD
iIDENTIFIER
:KEYWORD
1VALUE
toKEYWORD
vIDENTIFIER
writeKEYWORD
KEYWORD
helloVALUE
KEYWORD

According to the information that I am referring to at, https://www.geeksforgeeks.org/compiler-design/introduction-of-lexical-analysis/, there 2 columns needed, first one is lexemes and second one is tokens. How these tokens are to be used seems to be the next step.